()
| 69 | } |
| 70 | |
| 71 | func getTypeDocs() map[string]string { |
| 72 | fset := token.NewFileSet() |
| 73 | d, err := parser.ParseDir(fset, "./message", nil, parser.ParseComments) |
| 74 | if err != nil { |
| 75 | panic(err) |
| 76 | } |
| 77 | space := regexp.MustCompile(`\s+`) |
| 78 | typeDocs := map[string]string{} |
| 79 | for _, f := range d { |
| 80 | p := doc.New(f, "./message", 0) |
| 81 | for _, t := range p.Types { |
| 82 | typeDocs[t.Name] = space.ReplaceAllString(strings.Replace(t.Doc, "\n", " ", -1), " ") |
| 83 | previousName := "" |
| 84 | ast.Inspect( |
| 85 | t.Decl, func(node ast.Node) bool { |
| 86 | switch nodeType := node.(type) { |
| 87 | case *ast.TypeSpec: |
| 88 | previousName = nodeType.Name.Name |
| 89 | case *ast.StructType: |
| 90 | for _, field := range nodeType.Fields.List { |
| 91 | comment := space.ReplaceAllString(strings.Replace(field.Comment.Text(), "\n", " ", -1), " ") |
| 92 | for _, name := range field.Names { |
| 93 | if comment != "" { |
| 94 | typeDocs[previousName+"."+name.String()] = comment |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | return true |
| 100 | }, |
| 101 | ) |
| 102 | } |
| 103 | } |
| 104 | return typeDocs |
| 105 | } |
| 106 | |
| 107 | func document(entity interface{}, docs map[string]string) DocStruct { |
| 108 | t := reflect.TypeOf(entity) |
no test coverage detected