(inputPath string)
| 83 | } |
| 84 | |
| 85 | func ExtractStructs(inputPath string) (string, []*StructInfo, error) { |
| 86 | fset := token.NewFileSet() |
| 87 | |
| 88 | f, err := parser.ParseFile(fset, inputPath, nil, parser.ParseComments) |
| 89 | |
| 90 | if err != nil { |
| 91 | return "", nil, err |
| 92 | } |
| 93 | |
| 94 | packageName := f.Name.String() |
| 95 | structs := make(map[string]*StructInfo) |
| 96 | |
| 97 | for k, d := range f.Scope.Objects { |
| 98 | if d.Kind == ast.Typ { |
| 99 | incl, err := shouldInclude(d) |
| 100 | if err != nil { |
| 101 | return "", nil, err |
| 102 | } |
| 103 | if incl { |
| 104 | stobj := NewStructInfo(k) |
| 105 | |
| 106 | structs[k] = stobj |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | files := map[string]*ast.File{ |
| 112 | inputPath: f, |
| 113 | } |
| 114 | |
| 115 | pkg, _ := ast.NewPackage(fset, files, nil, nil) |
| 116 | |
| 117 | d := doc.New(pkg, f.Name.String(), doc.AllDecls) |
| 118 | for _, t := range d.Types { |
| 119 | if skipre.MatchString(t.Doc) { |
| 120 | delete(structs, t.Name) |
| 121 | } else { |
| 122 | if skipdec.MatchString(t.Doc) { |
| 123 | s, ok := structs[t.Name] |
| 124 | if ok { |
| 125 | s.Options.SkipDecoder = true |
| 126 | } |
| 127 | } |
| 128 | if skipenc.MatchString(t.Doc) { |
| 129 | s, ok := structs[t.Name] |
| 130 | if ok { |
| 131 | s.Options.SkipEncoder = true |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | rv := make([]*StructInfo, 0) |
| 138 | for _, v := range structs { |
| 139 | rv = append(rv, v) |
| 140 | } |
| 141 | return packageName, rv, nil |
| 142 | } |
no test coverage detected
searching dependent graphs…