@@ -121,6 +121,37 @@ func Read(folder string, ignoredFunctions []string, excludedFiles []string) (API
121121 return * result , nil
122122}
123123
124+ func interpretFieldType (f * ast.Field , expr ast.Expr ) []APIstructField {
125+ var fieldNames []APIstructField
126+ fieldType := expr
127+ switch t := fieldType .(type ) {
128+ case * ast.StarExpr :
129+ fieldType = t .X
130+ case * ast.ArrayType :
131+ fieldType = t .Elt
132+ if tt , ok := fieldType .(* ast.StarExpr ); ok {
133+ fieldType = tt .X
134+ }
135+ case * ast.MapType :
136+ fieldType = t .Value
137+ if tt , ok := fieldType .(* ast.StarExpr ); ok {
138+ fieldType = tt .X
139+ }
140+ fieldNames = interpretFieldType (f , t .Key )
141+ case * ast.Ident :
142+ // nothing to do
143+ case * ast.ChanType :
144+ fieldType = t .Value
145+ case * ast.StructType :
146+ // nothing to do
147+ case * ast.IndexExpr :
148+ fieldType = t .X
149+ fieldNames = interpretFieldType (f , t .Index )
150+ }
151+ fieldNames = append (fieldNames , APIstructField {Name : f .Names [0 ].Name , Type : ExprToString (fieldType )})
152+ return fieldNames
153+ }
154+
124155func readFile (ignoredFunctions []string , f * ast.File , result * API ) {
125156 for _ , d := range f .Decls {
126157 if str , isStr := d .(* ast.GenDecl ); isStr {
@@ -139,22 +170,7 @@ func readFile(ignoredFunctions []string, f *ast.File, result *API) {
139170 fieldNames = make ([]APIstructField , 0 , len (structType .Fields .List ))
140171 for _ , f := range structType .Fields .List {
141172 if len (f .Names ) > 0 {
142- fieldType := f .Names [0 ].Obj .Decl .(* ast.Field ).Type
143- switch t := fieldType .(type ) {
144- case * ast.StarExpr :
145- fieldType = t .X
146- case * ast.ArrayType :
147- fieldType = t .Elt
148- if tt , ok := fieldType .(* ast.StarExpr ); ok {
149- fieldType = tt .X
150- }
151- case * ast.MapType :
152- fieldType = t .Value
153- if tt , ok := fieldType .(* ast.StarExpr ); ok {
154- fieldType = tt .X
155- }
156- }
157- fieldNames = append (fieldNames , APIstructField {Name : f .Names [0 ].Name , Type : ExprToString (fieldType )})
173+ fieldNames = append (fieldNames , interpretFieldType (f , f .Names [0 ].Obj .Decl .(* ast.Field ).Type )... )
158174 } else {
159175 // Embedded struct
160176 fieldType := f .Type
0 commit comments