gpt4 book ai didi

go - 如何在 golang 中对包进行版本控制?

转载 作者:IT老高 更新时间:2023-10-28 13:05:43 33 4
gpt4 key购买 nike

我已经阅读了一大堆关于导入 3rd 方 go 包的文章和 SO 问题,这些问题看起来都很简单,但我不明白的是,我读过的所有文章都没有提到任何版本控制。在 Dartlang 中有一个 pubspec 文件,它定义了你的包,包括它的版本和它的依赖关系,包括它们所需的版本。如果我执行 go get github.com/gorilla/sessions 并编写我的应用程序,然后 6 个月后我必须清除我的目录并重新获取所有内容,此时该软件包已更新并且与我使用旧版本的代码的向后兼容性被破坏了?

最佳答案

正式版,来自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.

这种方法有很多替代方法,主要基于声明您正在使用的那些项目的确切版本。

参见例如“Dead Simple Dependencies in Go -- Keep it simple and keep your sanity.”(基于 emil2k/vend)

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

" Go Package Management -- A summary of dependency management in Go "
(及其同事GOPM mailing list)

2015 年 7 月更新:

2017 年第四季度更新:如前所述 below , go dep是固定版本依赖的官方工具(尽管这种固定方法并非没有批评:参见“The cargo cult of versioning”)。
当 Go 1.10 开发开始时,它应该被合并到工具链中,according to its roadmap .

2018 年第二季度更新:go dep 已替换为 go mod (modules) in Go 1.11 , following works on vgo .

关于go - 如何在 golang 中对包进行版本控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28698814/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com