go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

Mention GOFLAGS in documentation as we don't have a `-mod` flag

Open variadico opened this issue 5 years ago • 4 comments

This is more of a documentation ticket. This should probably make its way to the readme or some other document.

staticcheck will fail if you don't have git installed. This is because go list will "helpfully" try to install deps it thinks are missing.

The error looks like this:

$ staticcheck ./...
go [list -e -json -compiled -test=true -export=false -deps=true -find=false -tags= -- ./...]: exit status 1: go: github.com/lib/[email protected]: git init --bare in /root/go/pkg/mod/cache/vcs/01b4997f7dd5821a38fc67ad1dbddb0839f3fe66c76533286b350cb97434f24c: exec: "git": executable file not found in $PATH

If you use go build -mod vendor and have a vendor/ directory, then this will cause you problems. To make the -mod vendor setting global you have to set GOFLAGS.

export GOFLAGS="-mod=vendor"

Then staticcheck will work.

variadico avatar Jun 05 '19 23:06 variadico

Noted, we'll mention GOFLAGS in the docs.

See also https://github.com/golang/go/issues/27227 and https://github.com/golang/go/issues/30240

dominikh avatar Jun 06 '19 15:06 dominikh

GOFLAGS also helps to be able to specify -modfile

GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck

wallyqs avatar Oct 04 '21 22:10 wallyqs

Is GOFLAGS="-mod=vendor" still required since Go 1.14, which added autodetection of vendoring? https://go.dev/doc/go1.14#vendor

joeshaw avatar Mar 31 '22 14:03 joeshaw

If you want to use GOFLAGS="-modfile=go_test.mod" for example, yes would be required.

wallyqs avatar Mar 31 '22 15:03 wallyqs