go-tools
go-tools copied to clipboard
Mention GOFLAGS in documentation as we don't have a `-mod` flag
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.
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
GOFLAGS
also helps to be able to specify -modfile
GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck
Is GOFLAGS="-mod=vendor"
still required since Go 1.14, which added autodetection of vendoring? https://go.dev/doc/go1.14#vendor
If you want to use GOFLAGS="-modfile=go_test.mod"
for example, yes would be required.