英文:
Package versioning in Golang
问题
我对Golang项目中的软件包版本控制有一个问题。
在创建一个标签之后,比如v1.0.0,我可以使用go get pkg_address/@v1.0.0来获取这个标签,这样做是正确的。
但是当我在GitHub上看到Go软件包时,他们在安装部分写的是使用pkg_address/v1.0.0来安装软件包。
实际上,他们是在没有@的情况下拉取特定版本的软件包。
而且,他们甚至在代码中使用pkg_address/v1来导入软件包,尽管在项目中没有名为v1的目录。
如果我没有使用@来安装特定的标签,我会遇到错误。
即使在使用pkg_address/@v1.0.0之后,我的导入路径也不会改变,我不需要在导入路径中指定版本。
例如,你可以使用以下命令安装echo软件包:go get github.com/labstack/echo/v4,并在你的代码中使用v4标签导入该软件包,而在软件包目录中并没有v4。
我该如何像GitHub软件包一样进行版本控制?
附注:我正在使用GitLab。
英文:
I have a question about package versioning in Golang projects.
After creating a tag, for example v1.0.0.
I can pull this tag using go get pkg_address/@v1.0.0 which is fine and works correctly.
But when I see Go packages in github I see that it's written in their installation section to install the package using pkg_address/v1.0.0.
In fact they are pulling a specific version without @.
And they even import packages in their code using pkg_address/v1 even though there is no directory called v1 in their project.
I get error if I install a specific tag without @.
Even after using pkg_address/@v1.0.0 my import paths don't change and I don't need to specify version in my import paths.
For example you install echo package using this command go get github.com/labstack/echo/v4 and you import the package using the v4 tag in your code and there is no v4 in the package directories.
How can I do versioning like github packages?
P.S. I'm using gitlab.
答案1
得分: 2
这是一个模块路径命名约定,适用于高于v1的主要版本。
https://go.dev/ref/mod#module-path
- 如果模块发布的是主要版本2或更高,
模块路径必须以主要版本后缀结尾,例如/v2。这可能是子目录名称的一部分,也可能不是。例如,具有路径golang.org/x/repo/sub/v2的模块可以位于golang.org/x/repo的/sub或/sub/v2子目录中。
https://go.dev/ref/mod#major-version-suffixes
从主要版本2开始,
模块路径必须具有与主要版本匹配的主要版本后缀,例如/v2。例如,如果一个模块在v1.0.0版本具有路径example.com/mod,那么在v2.0.0版本必须具有路径example.com/mod/v2。
而echo的v4 模块路径可以在这里找到。
英文:
This is a module path naming convention and it applies to major versions higher than v1.
https://go.dev/ref/mod#module-path
> - If the module is released at major version 2 or higher, the module path MUST end with a major version suffix like /v2. This may or may
> not be part of the subdirectory name. For example, the module with
> path golang.org/x/repo/sub/v2 could be in the /sub or /sub/v2
> subdirectory of the repository golang.org/x/repo.
https://go.dev/ref/mod#major-version-suffixes
> Starting with major version 2, module paths MUST have a major
> version suffix like /v2 that matches the major version. For example,
> if a module has the path example.com/mod at v1.0.0, it must have the
> path example.com/mod/v2 at version v2.0.0.
And echo's v4 module path can be found here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论