如何在Golang中对软件包进行版本控制?

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

how to version packages in golang?

问题

我已经阅读了很多关于导入第三方Go包的文章和SO问题,它们都很简单明了,但我不明白的是,我所阅读的文章中没有提到版本控制。在Dartlang中,有一个pubspec文件,用于定义您的包及其版本以及其依赖项及其所需的版本。如果我执行go get github.com/gorilla/sessions并编写我的应用程序,然后6个月后我不得不清除我的目录并重新获取所有内容,在此期间该包已经更新并与使用旧版本的代码破坏了向后兼容性,那该怎么办呢?

英文:

I've read a whole bunch of articles and SO questions on importing 3rd party go packages which all seems straight forward, but what I don't understand is that none that I have read make any references to versioning. In Dartlang there's the pubspec file that defines your package including its version and its dependencies including their required versions. What if I do a go get github.com/gorilla/sessions and write my app then 6 months later I have to clear my directories and re get everything again, in which time that package has been update and broken backwards compatibility with my code that was using the older version?

答案1

得分: 25

官方版本,来自GO FAQ

> 如果你正在使用外部提供的包,并担心它可能以意想不到的方式发生变化,最简单的解决方案是将其复制到你的本地仓库中。(这是Google内部采用的方法。)将副本存储在一个新的导入路径下,以标识它为本地副本。

有许多其他方法可以实现这种方法,主要是基于声明你正在使用的那些项目的确切版本。

例如,参见“Go中的简单依赖管理--保持简单,保持理智”(基于emil2k/vend

Go依赖管理的主要不同选项列在:

Go包管理--Go中依赖管理的摘要
(以及其相关的GOPM邮件列表

更新于2015年7月:

2017年第四季度更新:如下所述,go dep是固定依赖版本的官方工具(尽管这种固定方法并非没有批评:参见“版本控制的模仿”)。
根据其路线图,当Go 1.10的开发开始时,它应该合并到工具链中。

2018年第二季度更新:go dep已被go mod(模块)Go 1.11取代,vgo的工作之后

英文:

The official version, from the GO FAQ:

> If you're using an externally supplied package and worry that it might change in unexpected ways, the simplest solution is to copy it to your local repository. (This is the approach Google takes internally.) Store the copy under a new import path that identifies it as a local copy.

There are many alternative to that approach, mainly based on declaring the exact version of those projects you are using.

See for instance "Dead Simple Dependencies in Go -- Keep it simple and keep your sanity." (based on emil2k/vend)

The main different options for Go Dependency Management are listed at:

"Go Package Management -- A summary of dependency management in Go"
(And its associate GOPM mailing list)

Update July 2015:

Update Q4 2017: as mentioned below, go dep is the official tool for pinning version of dependencies (even though that pinning approach is not without criticism: see "The cargo cult of versioning").
It should be merged into the toolchain when Go 1.10 development begins, according to its roadmap.

Update Q2 2018: go dep has been replaced by go mod (modules) in Go 1.11, following works on vgo.

答案2

得分: 2

我使用dep作为golang项目的依赖管理工具。请使用以下链接dep工具获取更多信息。

> dep是Go的依赖管理工具。它需要Go 1.9或更新版本进行编译。
>
>dep是一个“官方实验”。截至1.11版本,Go工具链(实验性地)采用了与dep截然不同的方法。因此,我们将继续开发dep,但主要将工作重点放在工具链中版本行为的替代原型的开发上。

**当前状态:**2019年1月
>dep在生产环境中是安全的。

英文:

I use dep as a dependency management tool for golang project. Please use the following link dep tool for more info.

> dep is a dependency management tool for Go. It requires Go 1.9 or newer to compile.
>
>dep was the "official experiment." The Go toolchain, as of 1.11, has (experimentally) adopted an approach that sharply diverges from dep. As a result, we are continuing development of dep, but gearing work primarily towards the development of an alternative prototype for versioning behavior in the toolchain.

Current status: January 2019
>dep is safe for production use.

huangapple
  • 本文由 发表于 2015年2月24日 22:47:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/28698814.html
匿名

发表评论

匿名网友

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

确定