TExcelTAD
Home › Go Modules in Depth › Mini Project: A Multi-Module Release

Mini Project: A Multi-Module Release

Time to put the course together. You'll build a small repository with three modules and release it the way a real team would:

Module Path Role
textkit/ example.com/textkit → example.com/textkit/v2 a public library, released as v1.0.0 and then, after a breaking change, as v2.0.0
auth/ corp.example/auth a private module: developed in a workspace, then published to a company proxy
app/ example.com/app the application: uses textkit v2 and auth, has free and pro editions (build tags) and a stamped version

The whole project is one verified session, split into steps with == step markers. It reuses the gopublish helper from Upgrades, exclude & retract; public-proxy/ plays the public mirror and corp-proxy/ the company proxy.

The plan

  1. Write textkit and publish v1.0.0.
  2. Make a breaking change and release it correctly as textkit/v2 v2.0.0.
  3. Write auth and app, wired together with a go.work workspace.
  4. Build both editions, with the version stamped from Git.
  5. Check what CI would see with GOWORK=off, then publish auth to the company proxy with the right GOPRIVATE/GONOPROXY settings, and require it properly.
  6. Release checks: go mod tidy -diff, go vet, tests, govulncheck, go version -m, and a cross build.

The session

bash · try it yourself
# gopublish DIR MODULE VERSION PROXYDIR: write one module version in GOPROXY layout
mkdir -p ~/tools/gopublish && cat > ~/tools/gopublish/main.go <<'SRC'
package main

import (
	"archive/zip"
	"os"
	"path/filepath"
)

func main() {
	dir, mod, ver := os.Args[1], os.Args[2], os.Args[3]
	at := filepath.Join(os.Args[4], mod, "@v")
	os.MkdirAll(at, 0o755)
	gomod, _ := os.ReadFile(filepath.Join(dir, "go.mod"))
	os.WriteFile(filepath.Join(at, ver+".mod"), gomod, 0o644)
	info := `{"Version":"` + ver + `","Time":"2026-01-15T10:00:00Z"}`
	os.WriteFile(filepath.Join(at, ver+".info"), []byte(info), 0o644)
	f, _ := os.Create(filepath.Join(at, ver+".zip"))
	z := zip.NewWriter(f)
	filepath.WalkDir(dir, func(p string, d os.DirEntry, err error) error {
		if !d.IsDir() {
			rel, _ := filepath.Rel(dir, p)
			w, _ := z.Create(mod + "@" + ver + "/" + filepath.ToSlash(rel))
			data, _ := os.ReadFile(p)
			w.Write(data)
		}
		return nil
	})
	z.Close()
	f.Close()
	list, _ := os.OpenFile(filepath.Join(at, "list"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
	list.WriteString(ver + "\n")
	list.Close()
}
SRC
(cd ~/tools/gopublish && go mod init gopublish 2>/dev/null && go build -o ~/go/bin/gopublish .)
mkdir -p repo && cd repo && git init -q
printf 'go.work\ngo.work.sum\nbin/\n' > .gitignore
export GOPROXY=file://$HOME/public-proxy,file://$HOME/corp-proxy,file:///opt/goproxy
export GOPRIVATE=corp.example GONOPROXY=none

echo "== step 1: textkit v1.0.0"
mkdir textkit && cd textkit
go mod init example.com/textkit 2>/dev/null
cat > textkit.go <<'SRC'
// Package textkit formats short messages.
package textkit

import "strings"

// Shout upper-cases a message and adds one exclamation mark.
func Shout(msg string) string { return strings.ToUpper(msg) + "!" }
SRC
cd ..
gopublish textkit example.com/textkit v1.0.0 ~/public-proxy

echo "== step 2: textkit v2.0.0 (breaking: Shout takes a count)"
cd textkit
go mod edit -module example.com/textkit/v2
cat > textkit.go <<'SRC'
// Package textkit formats short messages.
package textkit

import "strings"

// Shout upper-cases a message and adds n exclamation marks.
func Shout(msg string, n int) string { return strings.ToUpper(msg) + strings.Repeat("!", n) }
SRC
cat > textkit_test.go <<'SRC'
package textkit

import "testing"

func TestShout(t *testing.T) {
	if got := Shout("hi", 3); got != "HI!!!" {
		t.Fatalf("Shout = %q", got)
	}
}
SRC
go test ./...
head -1 go.mod
cd ..
gopublish textkit example.com/textkit/v2 v2.0.0 ~/public-proxy
go list -m -versions example.com/textkit example.com/textkit/v2

echo "== step 3: auth (private) + app, in a workspace"
mkdir auth && cd auth
go mod init corp.example/auth 2>/dev/null
cat > auth.go <<'SRC'
// Package auth decides who may use the pro features.
package auth

func IsLicensed(user string) bool { return user == "ada" }
SRC
cd .. && mkdir -p app && cd app
go mod init example.com/app 2>/dev/null
cat > main.go <<'SRC'
package main

import (
	"fmt"
	"runtime/debug"

	"corp.example/auth"
	"example.com/textkit/v2"
)

var version = "dev"

func main() {
	rev := "unknown"
	if info, ok := debug.ReadBuildInfo(); ok {
		for _, s := range info.Settings {
			if s.Key == "vcs.revision" {
				rev = s.Value[:7]
			}
		}
	}
	fmt.Printf("app %s (%s edition, rev %s)\n", version, edition, rev)
	fmt.Println(textkit.Shout("welcome", exclamations))
	fmt.Println("ada licensed:", auth.IsLicensed("ada"))
}
SRC
cat > edition_free.go <<'SRC'
//go:build !pro

package main

const (
	edition      = "free"
	exclamations = 1
)
SRC
cat > edition_pro.go <<'SRC'
//go:build pro

package main

const (
	edition      = "pro"
	exclamations = 3
)
SRC
go get example.com/textkit/v2@v2.0.0
cd ..
go work init ./app ./auth ./textkit
go work edit -dropuse ./textkit
cat go.work

echo "== step 4: both editions, stamped from Git"
git add . && git commit -qm "app, auth, textkit" && git tag app/v1.0.0
VERSION=$(git describe --tags --match 'app/*' | sed 's#^app/##')
go build -o bin/app -ldflags "-X main.version=$VERSION" ./app && ./bin/app
go build -tags pro -o bin/app-pro -ldflags "-X main.version=$VERSION" ./app && ./bin/app-pro

echo "== step 5: what CI sees without go.work"
(cd app && GOWORK=off go build -o /dev/null . 2>&1 | head -2)
gopublish auth corp.example/auth v1.0.0 ~/corp-proxy
(cd app && GOWORK=off go get corp.example/auth@v1.0.0 && GOWORK=off go mod tidy && GOWORK=off go build -o /dev/null . && echo "app builds on its own")
grep -E 'textkit|auth' app/go.sum | cut -d' ' -f1,2

echo "== step 6: release checks"
cd app
GOWORK=off go mod tidy -diff && echo "go.mod is tidy"
GOWORK=off go vet ./... && GOWORK=off go vet -tags pro ./... && echo "vet ok (free + pro)"
GOWORK=off govulncheck ./...
cd ..
git add . && git commit -qm "require published auth" && git tag app/v1.0.1
VERSION=$(git describe --tags --match 'app/*' | sed 's#^app/##')
cd app
GOWORK=off go build -tags pro -o ../bin/app-pro -ldflags "-X main.version=$VERSION" . && ../bin/app-pro | head -1
GOWORK=off CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -o ../bin/app-linux-arm64 -ldflags "-s -w -X main.version=$VERSION" .
cd ..
file bin/app-linux-arm64 | cut -d, -f1,2
go version -m bin/app-pro | grep -E '^\s(mod|dep)\s|-tags|vcs.modified'
== step 1: textkit v1.0.0
== step 2: textkit v2.0.0 (breaking: Shout takes a count)
ok  	example.com/textkit/v2	0.004s
module example.com/textkit/v2
example.com/textkit v1.0.0
example.com/textkit/v2 v2.0.0
== step 3: auth (private) + app, in a workspace
go: downloading example.com/textkit/v2 v2.0.0
go: added example.com/textkit/v2 v2.0.0
go 1.27.3

use (
	./app
	./auth
)
== step 4: both editions, stamped from Git
app v1.0.0 (free edition, rev 8f2d560)
WELCOME!
ada licensed: true
app v1.0.0 (pro edition, rev 8f2d560)
WELCOME!!!
ada licensed: true
== step 5: what CI sees without go.work
main.go:7:2: no required module provides package corp.example/auth; to add it:
	go get corp.example/auth
go: downloading corp.example/auth v1.0.0
go: added corp.example/auth v1.0.0
app builds on its own
corp.example/auth v1.0.0
corp.example/auth v1.0.0/go.mod
example.com/textkit/v2 v2.0.0
example.com/textkit/v2 v2.0.0/go.mod
== step 6: release checks
go.mod is tidy
vet ok (free + pro)
No vulnerabilities found.
app v1.0.1 (pro edition, rev d914921)
bin/app-linux-arm64: ELF 64-bit LSB executable, ARM aarch64
	mod	example.com/app	(devel)
	dep	corp.example/auth	v1.0.0	h1:Yxh/ayr9fgPTLwXp/WJSGgxbo2fp6Ffo3j51F64OJzE=
	dep	example.com/textkit/v2	v2.0.0	h1:/sjT0ofrJXZ5rdz7C82t/8WTJm1EfmGFMZPLaA+XjfI=
	build	-tags=pro
	build	vcs.modified=false

Walkthrough

Steps 1–2. textkit v2 changes Shout's signature, so it gets a new module path before the tag, exactly as in Releasing a v2. go list -m -versions shows two independent version lists.

Step 3. The app imports example.com/textkit/v2 (package name still textkit) and the private corp.example/auth. auth isn't published yet, so a workspace provides it. textkit was dropped from the workspace on purpose: the app should use the released v2.0.0 from the proxy, not the working copy. .gitignore keeps go.work out of the commit.

Step 4. Two editions from one source tree with //go:build pro / !pro (Build Tags & Constraints), and the version comes from a Git tag. In a multi-module repository, tags for the module in app/ carry an app/ prefix, which the sed strips; the revision comes from the embedded build info (Version Stamping).

Step 5. With GOWORK=off, the app fails exactly as it would in CI: nothing requires corp.example/auth. Publishing auth to the company proxy and running go get fixes that. Because GOPRIVATE=corp.example and GONOPROXY=none, the module comes through our proxy, and its hash still lands in go.sum (Private Modules & Proxies).

Step 6. The checks a release pipeline runs: tidy -diff, vet for both editions and govulncheck. Then the release itself: commit, tag app/v1.0.1, and build with GOWORK=off, as CI would. That matters: inside the workspace (step 4) the go command reports workspace modules as (devel), while the GOWORK=off build records real versions. go version -m confirms what went into the binary: textkit v2.0.0 and auth v1.0.0 with their hashes, the pro tag, and a clean work tree. The main module still shows (devel): unlike the single-module repository in Version Stamping, Go 1.27 did not derive a version for this module in a subdirectory from its prefixed app/v1.0.1 tag. That's why the session stamps the version with -X from git describe; don't rely on info.Main.Version alone in multi-module repositories. The ARM64 build is static (CGO_ENABLED=0) and stripped.

Extend it

  • Add a retract v2.0.0 scenario: publish a textkit v2.0.1 that retracts v2.0.0, and see go list -m -u all flag it.
  • Add a tool directive for stringer and generate the edition names with go generate.
  • Vendor the app (go mod vendor) and build it with GOPROXY=off from an empty module cache.
  • Write the GoReleaser configuration that would produce the same binaries for linux, darwin and windows (Toolkit).

Test yourself

Why was textkit dropped from the workspace in step 3?

  1. Workspaces can only hold two modules
  2. So the app builds against the released textkit/v2 v2.0.0 instead of the working copy
  3. Because textkit has tests
  4. go.work cannot contain v2 modules

What did the GOWORK=off build in step 5 reveal?

  1. A vulnerability
  2. That app/go.mod didn't require corp.example/auth; only the workspace made it build
  3. A cgo problem
  4. That textkit v2 was retracted

How is the version of the module in app/ tagged in this multi-module repository?

  1. v1.0.0
  2. app/v1.0.0
  3. example.com/app@v1.0.0
  4. v1.0.0-app