I'm trying to add a new package to my project with go modules. This package is using github.com/docker/docker/client and works fine outside of the project. When I run go mod vendor
it pulls docker client package of version v1.13.1 which does not have some of the methods I am using in my code, but in go modules it is tagged as latest. How do I make go mod use the truly latest version of a package?
When needed, more specific versions of dependencies can be chosen with commands such as
go get [email protected]
,go get foo@master
,go get foo@e3702bed2
, or by editinggo.mod
directly.
If you need the latest commit on the master
branch, use
go get github.com/docker/docker/client@master
This was driving me insane, too: Downloading the "master" or "latest" tag would often download versions one or two commits before HEAD. I found the answer here:
The go command defaults to downloading modules from the public Go module mirror at proxy.golang.org. It also defaults to validating downloaded modules, regardless of source, against the public Go checksum database at sum.golang.org. These defaults work well for publicly available source code.
And apparently there is some caching going on; if you wait a while it usually starts to work, alternatively it helps to temporarily set the version to a specific commit.
To fix it, I set GOPRIVATE=github.com/myuser
.
In this section, "latest" is the latest version with a semver tag, or the latest known commit if there are no semver tags. Prerelease tags are not selected as "latest" unless there are no other semver tags on the repository (details).
- github.com/golang/go/wiki/… –
Panslavism go env -w GOPROXY=direct
to disable this braindead behaviour. Thank you - I was going insane as well. –
Logger In order to get the latest un-tagged version, you need to specify the commit tag you want to have when doing go get
go get github.com/docker/docker/client@[commit-hash]
Would recommend using a specific version (preferred tagged version, if not latest pseudo version instead of master). Having dependency versions locked down in the go.mod file ensures repeatability.
The latest version available in one of the go proxies is https://search.gocenter.io/github.com~2Fdocker~2Fdocker/info?version=v1.14.0-0.20190511020111-3998dffb806f
go get github.com/docker/[email protected]
instead of go get github.com/docker/docker/[email protected]
–
Tahitian Spent the last 20 hours trying to fix a similar problem, in my case, the following steps solved the problem:
- delete
$GOPATH/pkg/sumdb
- delete the go.mod and go.sum files
- recreate the module: go mod init name
- go test ./...
My circumstances don't align perfectly with the original question, but I feel it may be worth mentioning to help others in situations similar to mine:
Context
- Was working with private modules, i.e., a Go module hosted from private git repository.
- Access to the private repo was not an issue.
- Would make and push changes to the private module.
- A program that imported the private module would consistently pull an old version when running
go get
, even after running:
go clean -modcache
rm go.sum
go get
go mod tidy
Root Cause: I'm an Idiot
- I had forgotten that Go uses VCS tagging with versioning.
- Failed to update the tag to match the current commit.
The Fix
- The version wasn't ready to be bumped (learning, here), so, in the private module, I ran the following command to align the version with the current commit:
- Note: This assumes that all repo content has been staged/committed/pushed.
In the private module repo
git tag -d v0.0.0
git push --delete v0.0.0
git tag v0.0.0
git push origin v0.0.0
In the repo that was importing the private repo
go clean -modcache
rm go.sum
go get
go mod tidy
© 2022 - 2024 — McMap. All rights reserved.
...@master
at the end is what makes it work! – Howe