Go Modules


If you are like me and getting errors while trying to compile your go lang code without having a go.mod in v1.18

package src is not in GOROOT (/usr/local/Cellar/go/1.18.3/libexec/src/src)

Remember you have overlooked a basic change that happened post 1.16

Module Aware Mode

The go command now builds packages in module-aware mode by default, even when no go.mod is present. 

Helpful Link

> go env|grep GO111

Set it off

go env -w GO111MODULE=off

Try again

go test
ok      _/Users/samarthya/sourcebox/github.com/git.golang/project-one/src        0.099s

You can also set GO111MODULE to auto to enable module-aware mode only when a go.mod file is present in the current directory or any parent directory.

go env -w GO111MODULE=auto