请在提交问题之前回答这些问题。 谢谢!
go version
)?去版本 go1.8.3 linux/amd64
go env
)?Ubuntu Linux,amd64
尝试在导入供应商依赖项的包上运行 golang.org/x/tools/cmd/stringer
该工具按预期工作
虽然 'go build' 和所有其他工具在 $GOPATH/src/vendor 中供应的依赖项似乎都很好,但 stringer 却因导入错误而失败:
$ go build plinth/auth
$ go get golang.org/x/tools/cmd/stringer
$ go generate plinth/auth
stringer: checking package: auth.go:8:2: could not import golang.org/x/net/context (can't find import: vendor/golang.org/x/net/context)
src/plinth/auth/auth.go:37: running "stringer": exit status 1
$ stringer -type Role $GOPATH/src/plinth/auth
stringer: checking package: [...]/src/plinth/auth/auth.go:8:2: could not import golang.org/x/net/context (can't find import: vendor/golang.org/x/net/context)
$ ls $GOPATH/src/vendor/golang.org/x/net/context
context.go context_test.go ctxhttp go17.go go19.go pre_go17.go pre_go19.go withtimeout_test.go
我们也遇到了这个问题。 它仅在 Go 1.8 下出现,如下所示: https://travis-ci.org/stripe/veneur/builds/278659663。 通过将相应拉取请求中的 Dockerfile 更改为使用 Go 1.8 而不是 Go 1.9,它可以在本地重现。 即使找不到的软件包(在本例中github.com/gogo/protobuf/proto
)安装了go install
,也会发生这种情况。
stringer 导入器对 1.8 使用默认的 Go 导入器,但对 1.9 不使用。
在运行 Stringer 之前,在当前项目中运行go install
(不是在它无法导入的包上,而是在提供导入的包上),然后再运行 Stringer 即可解决问题。
我试图在stringer
中解决这个问题,但我不确定为什么go/importer
本身的行为会以这种方式在 1.8 和 1.9 之间发生变化。 有人可以在这里指出我正确的方向吗?
这个问题在 Go 1.10 中得到修复,但最近又被重新引入。 我很确定引入它的提交是https://github.com/golang/tools/commit/ffe88906718454e356e61776b54256e873fc133b ,它恢复了 CL 40403。
提交被还原以解决https://github.com/golang/go/issues/25650 ,尽管它重新引入了相关的https://github.com/golang/go/issues/10249 。
我无法对这个问题发表评论,因为它最初由于年代久远而被锁定——它在两天前重新开放,但它仍然仅限于合作者。
@ChimeraCoder我解锁了#10249。
最有用的评论
@ChimeraCoder我解锁了#10249。