go - How to update imports when they change location
问题描述
I see that in Go you can import packages directly from Github like:
import "github.com/MakeNowJust/heredoc"
I understand that the path I am seeing in import line is not an URL, but only the path the package is located in (normally relative to $GOROOT/src/pkg or $GOPATH/src). So the package heredoc is most probably located in the directory $GOPATH/src/github.com/MakeNowJust/heredoc.
Now let's say that the package developer decided to migrate the code repo to Bitbucket. So now the library URL is bitbucket.com/muchMoreCoolerName/heredoc
. He also added some new features to the code repo.
My question is how will you get the updated code?
The only solution I can think of is changing all the imports to new URL and doing go get
again. But changing the code for library update seems a little inconvenient.
解决方案
如果您只是使用 go get 然后导入,则无法绕过它,您将不得不更新导入路径以获取新代码。但是,如果您使用供应商(一种使您的代码保持依赖关系并与它们一起分发的技术),那么至少在您更新之前,您将与该移动隔离。当您想要更新时,您可以使用供应商功能来保留旧的导入路径,但要与其他 repo 同步。
坦率地说,无论如何我仍然会使用供应商,当我决定更新时,只需搜索并替换旧的导入路径,这并不难。
编辑如果您还没有转换到模块,您还可以使用dep来管理依赖项。
推荐阅读
- amazon-web-services - 有没有办法用邮递员创建 AWS EC2 实例?
- python - GridSearchCV 的 sklearn 实现以什么顺序评估参数组合?
- arrays - rank 和 unrank 组合将 k 个球分配到 n 个不同容量的 bin 中
- android - Android Studio -- 在安卓手机中双重安装同一个项目
- ios - 使用 Swift 5 截屏会返回黑色图像,而不是应用程序的屏幕
- google-cloud-kms - 关于解开 KMS 加密密钥的 404 错误
- javascript - Webpack splitChunks 如何为每个 npm 包获取一个块(该块应该包含每个包的依赖项)
- java - 如果信号量锁获取/tryAcquire 失败,如何让 Java 线程执行不同的任务而不是阻塞?
- python-3.x - Pandas 导入 DataFrame 与整个库 - 速度和内存问题
- c - 无法在 Visual Studio 代码中构建 C 代码