[英]Is there a way to get ALL packages and dependencies of Go programs in a given directory and its subdirectories using Go standard tooling?
I have a large directory of Go packages which is actually my $GOPATH/src directory.我有一个很大的 Go 包目录,它实际上是我的 $GOPATH/src 目录。 I am trying to get a list of all packages (and their versions eventually if possible, but even names would be a nice start) within all subdirectories of that directory recursively (including the vendor directories).我正在尝试以递归方式获取该目录的所有子目录(包括供应商目录)中的所有软件包的列表(如果可能的话,最终还有它们的版本,但即使名称也是一个不错的开始)。 When I run go list all ./...
in $GOPATH/src, I get a bunch of messages saying:当我在 $GOPATH/src 中运行go list all ./...
时,我收到一堆消息:
code in directory [foo] expects import [bar]目录 [foo] 中的代码需要导入 [bar]
However, if I navigate to the individual package working directories, it seems to work.但是,如果我导航到单个包工作目录,它似乎可以工作。 I am also not sure why it actually does find the packages in the above command, but displays that error, which it does not display when I navigate down to each package's directory.我也不确定为什么它实际上确实在上面的命令中找到了包,但是显示了那个错误,当我向下导航到每个包的目录时它没有显示。 Is there a way to specify such a recursive lookup using the Go toolset?有没有办法使用 Go 工具集指定这样的递归查找?
I am also not sure why it actually does find the packages in the above command, but displays that error, which it does not display when I navigate down to each package's directory我也不确定为什么它实际上确实在上面的命令中找到了包,但是显示了那个错误,当我向下导航到每个包的目录时它没有显示
That seems to be the consequence of src/cmd/go/internal/load/pkg.go
这似乎是src/cmd/go/internal/load/pkg.go
if !cfg.ModulesEnabled && data.err == nil &&
data.p.ImportComment != "" && data.p.ImportComment != path &&
!strings.Contains(path, "/vendor/") && !strings.HasPrefix(path, "vendor/") {
data.err = fmt.Errorf("code in directory %s expects import %q", data.p.Dir, data.p.ImportComment)
}
In a non-module-enabled project, with vendor/
packages, you would get that error (as opposed to the same command run inside the vendor
folder, which would not trigger the condition shown above)在未启用模块项目,与vendor/
包,你会得到这个错误(而不是内部的相同的命令运行vendor
的文件夹,这将不会触发上面显示的条件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.