John,

Scott is on the money with this response:

> I think you need to have a main module defined so there must be a go.mod in 
> cwd or upwards

The way to ensure that you are in a valid module context is simply:

go env GOMOD

which will return the path to the current (or main) module context (go.mod) if:

a) you are in module mode (either by being outside of GOPATH or with
GO111MODULE=on) and
b) there is a go.mod on the directory path from $PWD to the root.

As you have set GO111MODULE=on you can put your source code pretty
much anywhere you like; even within your GOPATH (whether GOPATH is set
or not, in the latter case as has been pointed out it defaults to
$HOME/go)

All you are missing is a go.mod file (go end GOMOD would confirm this,
and would return "")

Here's a simple example that shows things working within GOPATH:

$ export GO111MODULE=on
$ export GOPATH=/tmp/tmp.JJgvIDI0Uc
$ cd /tmp/tmp.In4INnkIH0
$ mkdir -p src/example.com/blah
$ cd src/example.com/blah/
$ cat <<EOD >main.go
package main
func main() {}
EOD
$ go env GOMOD

$ go list
go: cannot find main module; see 'go help modules'
$ go mod init example.com/blah
go: creating new go.mod: module example.com/blah
$ go env GOMOD
/tmp/tmp.In4INnkIH0/src/example.com/blah/go.mod
$ go list
example.com/blah
$ go test
?       example.com/blah        [no test files]


Paul

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to