liveBook · Manning

Go workspace

As explained in Go in Action, Second Edition

A Go workspace is a development-time configuration that coordinates multiple Go modules so they can be developed and tested together without publishing versions.

A Go workspace lets related modules use one another’s local code during development without giving up independent releases. Each module keeps its own go.mod file and version. This is useful when a change crosses module boundaries but publishing a new version for every iteration would slow the work down. section 11.3 section 11.3.6

Put a go.work file at the repository root and list the modules being developed together. Go then resolves those modules to their local directories instead of downloading their published versions. The workspace changes development-time resolution; users importing a module still receive its published version, not the local code named in go.work. section 11.3.1

go work init ./domain ./storage

From the repository root, run `go work init ./domain ./storage` to create a workspace containing the domain and storage modules. Other modules can be added as they are created. section 11.3.1

Developing an RSS reader across modules

An RSS reader separates its domain model, bbolt storage implementation, REST API, and background worker into four modules. The API and worker can use local domain and storage code before those dependencies have published versions. Changes to a shared interface or storage implementation are available for cross-module testing without tagging a release. section 11.0 section 11.3.4

# Terminal 1: Run worker to fetch feeds
cd worker
go run ./cmd/worker

# Terminal 2: Run API to serve articles
cd api
go run ./cmd/api

# Terminal 3: Query the API
curl http://localhost:8080/articles?count=5

Run the worker and API as separate processes, then query the API. This checks the assembled application while both services resolve their shared modules locally. section 11.3.4

Use a workspace when related, independently versioned modules evolve together or need testing before publication. A single-module project needs only package organization; a stable external dependency can remain a versioned requirement in go.mod. A workspace coordinates development rather than replacing module boundaries or releases. section 11.3.6

How Go in Action, Second Edition covers it

How deep it goes
Explains go.work resolution, independent releases, initialization, and integration testing; does not detail workspace-file syntax beyond initialization.
Examples
Uses an RSS reader with domain, storage, API, and worker modules, plus a worker–API integration test.
What it assumes
Assumes familiarity with packages, modules, and go.mod; starts workspace setup after a domain module has been versioned.
What you can do after
Operate/configure it by initializing a workspace for local modules and testing services together before publishing dependency versions.
How it connects
Connects packages, Go modules, go.mod, domain interfaces, dependency inversion, and integration testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.