Home > Net >  Package versioning in Golang
Package versioning in Golang

Time:09-03

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.

CodePudding user response:

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.

  •  Tags:  
  • go
  • Related