尝试解析包内工具
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"zire/internal/tools"
|
"zire/internal/tools"
|
||||||
|
|
||||||
"golang.org/x/tools/go/packages"
|
"golang.org/x/tools/go/packages"
|
||||||
@@ -24,8 +25,18 @@ func main() {
|
|||||||
pkgs, err := packages.Load(cfg, "./...")
|
pkgs, err := packages.Load(cfg, "./...")
|
||||||
tools.Check(err, "加载包失败")
|
tools.Check(err, "加载包失败")
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
|
fmt.Println("当前包")
|
||||||
fmt.Println(pkg.Name)
|
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