英文:
Error in vendoring of third party library(mgo.v2)
问题
我正在尝试获取mgo.v2当前代码库的本地副本。https://gopkg.in/mgo.v2上说要使用go get gopkg.in/mgo.v2
进行安装。我从https://github.com/go-mgo/mgo/tree/v2进行了fork,并尝试从go get forked repo from git安装,但它改变了包的结构(从/src/gopkg.in --> /src/github.com),并且失败并显示以下错误:
src/github.com/eateshk/mgo.v2/error.go:4: "ERROR: the correct import path is gopkg.in/mgo.v2 ..." evaluated but not used
我理解这个错误,但是解决方法是什么?
英文:
I am trying to have a local copy of current code base of mgo.v2. https://gopkg.in/mgo.v2 says to install using go get gopkg.in/mgo.v2
. I forked it from https://github.com/go-mgo/mgo/tree/v2 and trying to install it from go get forked repo from git but it changes the package structure(changes from /src/gopkg.in --> /src/github.com) and it fails saying
src/github.com/eateshk/mgo.v2/error.go:4: "ERROR: the correct import path is gopkg.in/mgo.v2 ... " evaluated but not used
I understand the error, but what's the solution for this ?
答案1
得分: 1
这是在分叉Go包时常见的问题。规范或“虚拟”导入要求代码位于指定的路径中,否则无法编译。唯一的解决方法是删除某处存在的// import "gopkg.in/whatever"
注释。
你的方法还存在其他问题。在其存储库中的导入将会回溯到原始存储库,并且会导致各种混乱,除非你对它们进行重写。
相反,我建议采用另一种方法。唯一不会引起问题的磁盘上的位置是$GOPATH/src/gopkg.in/mgo.v2
。其他任何位置都会引起问题。所以:
go get gopkg.in/mgo.v2
cd $GOPATH/src/gopkg.in/mgo.v2
git remote add mine your_git_fork
现在你可以从origin
拉取上游更改,并将你的更改推送到mine
。这感觉有点奇怪,但这确实是在分叉时避免大量额外麻烦的唯一方法。
英文:
This is a common problem when forking go packages. Canonical or "vanity" imports require the code to live in the specified path or they won't compile. The only solution is to remove the // import "gopkg.in/whatever"
comment that exists somewhere.
There are other problems with your approach as well. imports within their repository will resolve back to the original repo and cause all kinds of confusion unless you rewrite them.
Rather, I suggest an alternate approach. The only place this can live on disk without causing problems is $GOPATH/src/gopkg.in/mgo.v2
. Anything else will cause problems. So:
go get gopkg.in/mgo.v2
cd $GOPATH/src/gopkg.in/mgo.v2
git remote add mine your_git_fork
Now you can pull upstream changes from origin
and push your changes to mine
. It feels a bit odd, but it really is the only way to work from a fork without causing tons of extra pain by rewriting things.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论