Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go modules pulls old version of a package

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?

like image 494
navigante Avatar asked Aug 30 '19 08:08

navigante


People also ask

How do I update Go modules?

You can upgrade or downgrade a dependency module by using Go tools to discover available versions, then add a different version as a dependency. To discover new versions use the go list command as described in Discovering available updates.

What is the difference between Go module and package?

In Go, a package is a directory of .go files, and packages form the basic building blocks of a Go program. Using packages, you organize your code into reusable units. A module, on the other hand, is a collection of Go packages, with dependencies and versioning built-in.

What Go mod tidy do?

go mod tidy ensures that the go. mod file matches the source code in the module. It adds any missing module requirements necessary to build the current module's packages and dependencies, if there are some not used dependencies go mod tidy will remove those from go.

Is Gopath required with Go modules?

With Go modules, you do not need to keep your project files under GOPATH and can easily manage dependencies in your project. Read more about Go modules at go.


2 Answers

Go Wiki: Modules:

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 editing go.mod directly.

If you need the latest commit on the master branch, use

go get github.com/docker/docker/client@master
like image 156
icza Avatar answered Oct 08 '22 21:10

icza


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.

like image 6
knipknap Avatar answered Oct 08 '22 22:10

knipknap