Using submodules is a way to nest multiple Go module projects you can edit.
But Go 1.18 might include the notion of Go workspace, which means you don't need submodules anymore: one Go project can include multiple modules you can edit.
See golang/go
issue 45713: "proposal: cmd/go
: add a workspace mode " and its design document.
Background
Users often want to make changes across multiple modules: for instance, to introduce a new interface in a package in one module along with a usage of that interface in another module.
Normally, the go
command recognizes a single "main
" module the user can edit.
Other modules are read-only and are loaded from the module cache.
The go mod replace
directive is the exception: it allows users to replace the resolved version of a module with a working version on disk.
But working with the replace
directive can often be awkward: each module developer might have working versions at different location on disk, so having the directive in a file that needs to be distributed with the module isn't a good fit for all use cases.
Proposal
This proposal describes a new workspace mode in the go
command for editing multiple modules.
The presence of a go.work
file in the working directory or a containing directory will put the go
command into workspace mode.
The go.work
file specifies a set of local modules that comprise a workspace. When invoked in workspace mode, the go
command will always select these modules and a consistent set of dependencies.
Main modules: The module the user is working in.
Before this proposal, this is the single module containing the directory where the go
command is invoked. This module is used as the starting point when running MVS.
This proposal proposes allowing multiple main modules.
See for instance CL 334934 (CL = Change List)
[dev.cmdgo
] cmd/go
: add the workspace mode
This change adds the outline of the implementation of the workspace mode.
The go
command will now locate go.work
files, and read them to determine
which modules are in the workspace.
It will then put those modules in the root of the workspace when building the build list.
It supports building, running, testing, and listing in workspaces.
You can initiate a multiple-module project with go mod initwork
Again, this is not before Go 1.18 (Q1 2022) and will probably be opt-in in Go 1.19 (Q3 2022).