本地导入非本地包

huangapple go评论82阅读模式
英文:

Local import in non-local package

问题

我知道应该避免使用本地导入,但在这种情况下,特殊情况需要它。这是一个私有仓库,在使用绝对URL时,由于服务器上缺少私钥,heroku构建包在go get ./...阶段失败。

现在我得到了这个错误非本地包中的本地导入“..”

所有导入路径都已更改为本地版本,那么什么才能使一个包被称为“非本地”?我该如何解决这个问题?

英文:

I know local imports should be avoided, however special circumstances demand it in this case. It's a private repo, and the heroku buildpack fails in the go get ./... phase when used with absolute urls, due to a missing private key on the server.

Now I get this error local import ".." in non-local package.

All import paths were changed to the local version so what remains that qualifies a package as "non-local"? How do I fix this?

答案1

得分: 5

我修复了它。问题是根包在$GOPATH/src/<host>/<user>/<package>中。一旦我将包移动到~/Git/<package>,错误就消失了(因此,"使其本地")。

英文:

I fixed it. The issue was that the root package was in $GOPATH/src/&lt;host&gt;/&lt;user&gt;/&lt;package&gt;. As soon as I moved the package to ~/Git/&lt;package&gt; the errors were gone (thus, "made it local").

答案2

得分: 0

peterSo是正确的。查看生成该错误消息的代码,如果加载的包没有以/ ./或../开头,但导入了一个以这些开头的包,就会发生这种情况。在您的问题中,有几个可能导致此问题的原因。

  1. go get导致构建了一个以非本地路径引用的依赖包,然后又加载了一个本地路径。
  2. 您正在使用go get获取一个包含本地导入的非本地包路径。

我认为您应该修复服务器上缺失的私钥问题,而不是尝试使用本地路径。

要正确调试,我需要知道您获取了哪些包以及它们的传递依赖关系。

最后一个问题是,为什么您要使用go get进行本地路径安装(例如go get ./...)?在这种情况下,通常应该使用go install或go build。

英文:

peterSo is right. Looking at the code where that error message gets generated it would happen if the package being loaded didn't start with / ./ or ../ but it imported one that did. In the case of your issue there are several things that could cause it.

  1. go get caused a dependent package referenced with a non-local path to be build which then loaded in turn a local path.
  2. you are go getting a non-local package path that includes a local import.

I think perhaps you should just fix the missing private key issue on the server rather than trying to use a local path.

To properly debug I'd need to know what packages exactly that you were getting and what their transitive dependencies were.

One last thing why are you using go get for local path installation (ie. go get ./...)? go install or go build are usually what you want in that case.

答案3

得分: -1

一个本地包导入路径是一个绝对文件系统路径,或者以./或../开头。一个非本地包导入路径不是一个本地包导入路径。

英文:

> A local package import path is an absolute file system path or one
> beginning with ./ or ../. A non-local package import path is not a
> local package import path.
>
> cmd/go/pkg.go

huangapple
  • 本文由 发表于 2013年2月4日 08:57:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/14679130.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定