diff --git a/console/commands/bean.go b/console/commands/bean.go index 9ea21d1..dd1b3b5 100644 --- a/console/commands/bean.go +++ b/console/commands/bean.go @@ -60,7 +60,7 @@ func (BeanCommand) Execute(input command.Input) { skip[s] = true } - fileList := parser.NewAst(scan) + fileList := parser.NewAst(scan, skip) var keys []string for s, _ := range fileList { keys = append(keys, s) diff --git a/parser/goast.go b/parser/goast.go index df08358..bf12d49 100644 --- a/parser/goast.go +++ b/parser/goast.go @@ -9,9 +9,9 @@ import ( "strings" ) -func NewAst(path string) map[string][]GoFileParser { +func NewAst(path string, skips ...map[string]bool) map[string][]GoFileParser { got := make(map[string][]GoFileParser) - for _, dir := range GetChildrenDir(path) { + for _, dir := range GetChildrenDir(path, skips...) { arr := make([]GoFileParser, 0) for _, file := range dir.GetFiles(".go") { if strings.Index(file.Name(), "_gen.go") != -1 { @@ -114,8 +114,11 @@ func getAstGoFileParser(fileName string) GoFileParser { if _, ok := expr.Key.(*ast.SelectorExpr); ok { attr.TypeName = "map todo" attr.InPackage = true - } else { - attr.TypeName = expr.Key.(*ast.Ident).Name + } else if iv, ok := expr.Key.(*ast.Ident); ok { + attr.TypeName = iv.Name + attr.InPackage = true + } else if iv, ok := expr.Key.(*ast.StarExpr); ok { + attr.TypeName = iv.X.(*ast.Ident).Name attr.InPackage = true } } else if _, ok := field.Type.(*ast.ArrayType); ok { diff --git a/parser/help_file.go b/parser/help_file.go index f765051..1b9987e 100644 --- a/parser/help_file.go +++ b/parser/help_file.go @@ -48,7 +48,14 @@ func (di DirInfo) GetFiles(ext string) []FileInfo { } // GetChildrenDir 获取目录和所有子目录 -func GetChildrenDir(path string) []DirInfo { +func GetChildrenDir(path string, skips ...map[string]bool) []DirInfo { + for _, skip := range skips { + for s := range skip { + if strings.Index(path, s) != -1 { + return nil + } + } + } got := []DirInfo{ { Name: filepath.Base(path), @@ -68,7 +75,7 @@ func GetChildrenDir(path string) []DirInfo { Name: file.Name(), Path: path + "/" + file.Name(), }) - next := GetChildrenDir(path + "/" + file.Name()) + next := GetChildrenDir(path+"/"+file.Name(), skips...) for _, s := range next { if s.Path != path+"/"+file.Name() { got = append(got, s)