尝试解析包内工具
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"zire/internal/tools"
|
||||
|
||||
"golang.org/x/tools/go/packages"
|
||||
@@ -24,8 +25,18 @@ func main() {
|
||||
pkgs, err := packages.Load(cfg, "./...")
|
||||
tools.Check(err, "加载包失败")
|
||||
for _, pkg := range pkgs {
|
||||
fmt.Println("当前包")
|
||||
fmt.Println(pkg.Name)
|
||||
fmt.Println(pkg.TypesInfo.Scopes)
|
||||
scope := pkg.Types.Scope()
|
||||
reg := regexp.MustCompile(".Provider")
|
||||
fmt.Println("寻找提供者")
|
||||
for _, name := range scope.Names() {
|
||||
if !reg.MatchString(name) {
|
||||
continue
|
||||
}
|
||||
fmt.Println(name)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user