1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 05:00:54 +00:00

ignore other type

This commit is contained in:
Yu Huang 2021-05-22 10:26:33 -04:00
parent 70c4a5f5f0
commit c3bb85f7b1

View File

@ -24,7 +24,7 @@ var builtInTypeMap = map[string]interface{}{
type StructField struct { type StructField struct {
Name string Name string
Type string Type ast.Expr
NestedType *StructNode NestedType *StructNode
Comment string Comment string
Doc string Doc string
@ -32,7 +32,7 @@ type StructField struct {
} }
func (sf *StructField) IsBuiltInType() bool { func (sf *StructField) IsBuiltInType() bool {
_, found := builtInTypeMap[sf.Type] _, found := builtInTypeMap[fmt.Sprint(sf.Type)]
return found return found
} }
@ -41,12 +41,19 @@ func (sf *StructField) Key() string {
} }
func (sf *StructField) Value() interface{} { func (sf *StructField) Value() interface{} {
val, found := builtInTypeMap[sf.Type] switch sf.Type.(type) {
if found { case *ast.Ident:
return val 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 { type StructNode struct {
@ -116,7 +123,7 @@ func (cg *ConfigGenerator) ToJSON() ([]byte, error) {
func ParseField(field *ast.Field) *StructField { func ParseField(field *ast.Field) *StructField {
fieldName := field.Names[0].Name fieldName := field.Names[0].Name
fieldType := fmt.Sprint(field.Type) fieldType := field.Type
fieldTag := "" fieldTag := ""
if field.Tag != nil { if field.Tag != nil {
@ -165,7 +172,13 @@ func ParseField(field *ast.Field) *StructField {
case *ast.SelectorExpr: // third party 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 { func ParseStruct(structName string, s *ast.StructType) *StructNode {