So the below worked. I had to manual create the directories and then execute the ‘go mod init’ command from that directory.
My expectation was that ‘go mod init’ would be smart enough to know read my $GOPATH and determine that directory didn’t exist and create it for me and then place the go.mod file there.
Guess I need to lower my expectations.
cadayton@Popsu:~/go/example/hello69$ go mod init example/hello69
go: creating new go.mod: module example/hello69
bash: /home/cadayton/go: Is a directory
What does this mean? Are you trying to say that you are confused because the example usage includes a URL? You don’t have to use a URL. You can go mod init neverontheinternet if you want.
It would probably be more productive to read the manual / getting started guides. I’m not sure why you are expecting go mod init to read your $GOPATH and set and place a go.mod file there. Start here:
A module is a collection of Go packages stored in a file tree with a go.mod file at its root. The go.mod file defines the module’s module path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build. Each dependency requirement is written as a module path and a specific semantic version.
As of Go 1.11, the go command enables the use of modules when the current directory or any parent directory has a go.mod, provided the directory is outside$GOPATH/src. (Inside $GOPATH/src, for compatibility, the go command still runs in the old GOPATH mode, even if a go.mod is found. See the go command documentation for details.) Starting in Go 1.13, module mode will be the default for all development.
What are you trying to do? It’s 2023 so you should probably not worry about $GOPATH and instead use go modules unless you have a specific reason (like working on a very old project; nearly everything has migrated to go modules these days). Why are you even worried about your $GOPATH?
There are a lot of other helpful getting started guides here:
You might want to specifically check this out:
If you have a specific problem/question, I’m sure people here (or on r/golang or the gopher discord server) would be happy to help you out.