As others had said, it can be much easier to just place everything in a single unpublished module rather than breaking things apart into multiple modules. This makes it much easier to stay on the "happy path", and for your situation it sounds like that would work.
That said, if you upgrade to Go 1.18, the new workspace feature makes it much easier to work with editing multiple local modules simultaneously:
With multi-module workspaces, you can tell the Go command that you’re writing code in multiple modules at the same time and easily build and run code in those modules.
For example, from a parent directory that contains multiple module directories underneath (each with their own go.mod files), you can create a go.work
file and recursively add the modules underneath by doing:
$ go work init
$ go work use -r .
If for example you have two modules and let's say module foo
imports module bar
, the resulting go.work file could then look like:
$ cat go.work
go 1.18
use (
./foo
./bar
)
If you then cd to the foo
directory, commands like go build
will use the local copies of both foo
and bar
.
The mechanics are that the go
command checks to see if it is inside of a directory tree with a go.work
file, and by default it consults any go.work
file found to help resolve where a dependency is located.
For more information on workspaces, there is a good tutorial here:
https://go.dev/doc/tutorial/workspaces
Alternatively, you can use the older technique of adding replace
directives to your individual go.mod files, but that is not as nice as the new go.work
feature.
Finally, even taking into account the new go.work
capabilities, it is worth reiterating that your life is simpler if you are only working with one module at a time, so don't needlessly cut up what could be a single module.