I am trying to make a Taskfile.yml file for building go application, but I can't quite understand the need of "GOFLAGS=-mod=mod" command before go build main.go.
reference: https://dev.to/aurelievache/learning-go-by-examples-part-3-create-a-cli-app-in-go-1h43
So there are two things here
GOFLAGS
GOFLAGS
variable has a space separated list of flags that will automatically be passed to the appropriate go commands.mod
, this flag is applicable to the go build
command and may not be applicable to other go commands.go
does this, refer to this change request-mod=mod
flag, actually do during go build
?
-mod
flag controls whether go.mod may be automatically updated and whether the vendor directory is used.-mod=mod
tells the go command to ignore the vendor directory and to automatically update go.mod, for example, when an imported package is not provided by any known module.Therefore
GOFLAGS="-mod=mod" go build main.go
is equivalent to
go build -mod=mod main.go