Working Across Go Modules

Develop several local modules together with go.work workspaces and fetch private modules with GOPRIVATE and git credentials.

Real projects often span more than one module, and some of those modules are private. This section covers both situations.

Go Workspaces with go.work

go work init ./app ./mathx

Local modules build against each other without replace lines. Usually keep go.work out of version control.

Private Modules and GOPRIVATE

go env -w GOPRIVATE=github.com/acme/*

Plus git credentials through SSH or a token, locally and in CI.

terminal prompts disabled:

This git error means it needs credentials but cannot ask for them. Set up SSH or a token.

Summary

Use workspaces for local multi-module work, and GOPRIVATE plus git credentials for private code.

Go Workspaces with go.work

Develop several Go modules together with go work init and go work use, without adding replace lines to go.mod, and know when to commit go.work.

Private Go Modules and GOPRIVATE

How to go get a private GitHub or GitLab repository, fix terminal prompts disabled and 410 Gone errors, and set GOPRIVATE, git credentials and CI access.