Importing specific versions of packages
Sometimes, you need a specific version of a third-party package because of API incompatibilities or a particular behavior you depend on.
How to do it...
- To get a specific version of a package, specify the version label:
$ go get modernc.org/[email protected]
- To get the latest release of a specific major version of a package, use this:
$ go get gopkg.in/yaml.v3
Alternatively, use this:
$ go get github.com/ory/dockertest/v3
- To import the latest available version, use this:
$ go get modernc.org/sqlite
- You can also specify a different branch. The following will get a module from the
devel
branch, if there is one:$ go get modernc.org/sqlite@devel
- Alternatively, you can get a specific commit:
$ go get modernc.org/sqlite@a8c3eea199bc8fdc39391d5d261eaa3577566050
As you can see, you can get a specific revision of a module using the @
revision
convention:
$ go get modernc.org/[email protected]
The revision part of the URL is evaluated by the version control system, which, in this case, is git
, so any valid git
revision syntax can be used.
Tip:
You can find which revision control systems are supported by checking out the src/cmd/go/alldocs.go
file under your Go installation.
That also means you can use branches:
$ go get modernc.org/sqlite@master
Tip
The https://gopkg.in service translates version numbers to URLs compatible with the Go build system. Refer to the instructions on that website on how to use it.