The Go compiler can compile the Go source go with different go specs. Fo example, if you have installed go 1.14, you can compile your source with Go spec 1.13.
The rules for which version of the Go spec used during compilation appear to be
- If your source code is stored within the
GOPATH(or you have disabled modules withGO111MODULE=off) then the version of the Go spec used to compile matches the version of the compiler you are using. ie if you have go 1.13(GOROOTpoints to yourgoinstallation) installed then the go spec used will be 1.13 - If your source code is outside the
GOPATH(orGO111MODULE=on), then the go tool will take the version from thego.modfile - If no
go.modfile is provided, then same as point 1 - If you are in module mode(see point 2) and no version is specified in the
go.modfile, thengo 1.13is used by default
The last point is interesting.
Reference: https://www.jetbrains.com/help/go/configuring-goroot-and-gopath.html