douqiang5163 2015-11-09 14:20
浏览 101
已采纳

GoLang中第三方库(mgo.v2)的供应错误

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条回答 默认 最新

  • douke3335 2015-11-09 17:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试