cmd/go: rough UX for developing multiple modules in one repository #39993
Labels
FrozenDueToAge
GoCommand
cmd/go
modules
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Untested.
What operating system and processor architecture are you using (
go env
)?Windows 10, amd64.
go env
OutputWhat did you do?
I encountered a frustrating scenario with Go Modules, while helping another Go programmer. I’m filing an issue because we feel it exposed some rough edges in Go Modules behaviour.
We have a private repository containing a Go gRPC server (“X”) with proto code, and a Go gRPC client (“Y”).
The relevant directory structure is as follows:
X contains a sub-package,
proto
, with the proto file and autogenerated Go proto code. Both X and Y’s main packages need to importproto
.We were able to build X without issue. We found that Y failed to build, due to a failure to fetch x/proto from Github. As far as I can tell, this is expected Go Modules behaviour: external packages are fetched from source.
This raised issues around how to handle private repository with Go Modules infrastructure. It also raised issues with how to easily develop and prototype, as even if the repository was public, the newly-written X was not yet pushed to upstream.
We attempted to use the
replace
directive, to explicitly point to the local copy ofproto
. This proved challenging, as Go Modules requires a git-based version specified in the dependency. We worked around this issue by committing/x
, and manually writing thev0.0.0-time-sha
version. This workaround allowed us to import/x
, but not/x/proto
. Error messaging led us to experiment with defining a separatego.mod
in/x/proto
, but we were unable to make that approach work.We resolved he issue by moving
proto
out of the server, into its own top-level module:X and Y were both able to import
proto
successfully.What did you expect to see?
We expected to be able to import the local copy of
/x/proto
, in both/x
and/y
codebasesWhat did you see instead?
Overall, this was a frustrating time waste, especially for a new programmer. To summarize the main issues:
proto
to a top-level package was perfectly acceptable).The text was updated successfully, but these errors were encountered: