add: 加速扫描过滤的目录

This commit is contained in:
yuanzhao
2024-04-12 15:53:51 +08:00
parent 9ab309aef7
commit 694baf713b
3 changed files with 17 additions and 7 deletions

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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)