DEV Community

Discussion on: Why is GO111MODULE everywhere, and everything about Go Modules (updated with Go 1.20)

Collapse
 
maelvls profile image
Maël Valais

Using GO111MODULE=off, you are falling back on the GOPATH method of installing the binary. In GOPATH mode, the master branch is always going to be the one checked out.

With GO111MODULE=on, you can rely on versions (i.e, git tags). The command

(cd && GO111MODULE=on go get -u golang.org/x/tools/cmd/goimports)
Enter fullscreen mode Exit fullscreen mode

will fetch the latest tag. The great benefit of this method is that you can pin-point the version to a branch or a tag or a commit:

(cd && GO111MODULE=on go get -u golang.org/x/tools/cmd/goimports@2363391)
Enter fullscreen mode Exit fullscreen mode

And since Go 1.16, the command has been greatly simplified (as long as there is no replace directive in goimport's go.mod):

go install golang.org/x/tools/cmd/goimports@2363391
Enter fullscreen mode Exit fullscreen mode