From c3bb85f7b10660bd9a1347eee9c5e15736e88dfb Mon Sep 17 00:00:00 2001 From: Yu Huang Date: Sat, 22 May 2021 10:26:33 -0400 Subject: [PATCH] ignore other type --- parser/parser.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index 28ca6ff..dcc2b28 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -24,7 +24,7 @@ var builtInTypeMap = map[string]interface{}{ type StructField struct { Name string - Type string + Type ast.Expr NestedType *StructNode Comment string Doc string @@ -32,7 +32,7 @@ type StructField struct { } func (sf *StructField) IsBuiltInType() bool { - _, found := builtInTypeMap[sf.Type] + _, found := builtInTypeMap[fmt.Sprint(sf.Type)] return found } @@ -41,12 +41,19 @@ func (sf *StructField) Key() string { } func (sf *StructField) Value() interface{} { - val, found := builtInTypeMap[sf.Type] - if found { - return val + switch sf.Type.(type) { + case *ast.Ident: + val, found := builtInTypeMap[fmt.Sprint(sf.Type)] + if found { + return val + } + return sf.NestedType.ToKV() + case *ast.ArrayType: + case *ast.MapType: + case *ast.SelectorExpr: // third party } - return sf.NestedType.ToKV() + return "" } type StructNode struct { @@ -116,7 +123,7 @@ func (cg *ConfigGenerator) ToJSON() ([]byte, error) { func ParseField(field *ast.Field) *StructField { fieldName := field.Names[0].Name - fieldType := fmt.Sprint(field.Type) + fieldType := field.Type fieldTag := "" if field.Tag != nil { @@ -165,7 +172,13 @@ func ParseField(field *ast.Field) *StructField { case *ast.SelectorExpr: // third party } - return nil + return &StructField{ + Name: fieldName, + Type: fieldType, + Tag: fieldTag, + Comment: fieldComment, + Doc: fieldDoc, + } } func ParseStruct(structName string, s *ast.StructType) *StructNode {