Workspaces
Start with Go Workspaces
A Go workspace coordinates development across multiple modules without rewriting their published module paths.
What you’ll learn
- Explain the main purpose of go workspaces.
- Read and run the complete Go example in this lesson.
- Apply the concept and recognize common mistakes.
Understand the idea
Use go work init ./app ./shared to create a workspace listing neighboring modules. The generated go.work file has use directives pointing at their directories. Go can then resolve code from those local modules as a set.
Workspaces are for multi-module development and do not replace the module metadata each module needs independently. Be careful about committing a workspace containing local-only directory paths that teammates cannot use.
Visualize how it works
Follow this diagram before executing the example. Check where a value or decision changes what runs next.
Tools, syntax and practical notes
Workspace example
go work init ./app ./shared
go work use ./shared
go work syncgo 1.23
use (
./app
./shared
)Initialize both modules first; version is illustrative and should match a suitable installed Go version.
Run a complete Go example
This example is a complete program. Save it as main.go or paste it into the Go Playground.
Go code
package main
import "fmt"
func main() {
modules := []string{"./app", "./shared"}
for _, folder := range modules {
fmt.Println("Workspace module:", folder)
}
}
Output
Workspace module: ./app
Workspace module: ./sharedTrace what the program does
The program prints the two local module folders. The actual workspace is defined by go.work, which is created and interpreted by the Go command.
Avoid common mistakes
- go.work is not a substitute for go.mod within each module.
- A workspace can hide missing published dependency declarations until each module is tested independently.
Try it yourself
Make app/ and shared/ modules, then create a workspace and try go work use ./shared.
Tip: Edit the example above, predict the output, and run the modified code to test your reasoning.
Check your understanding
What you should remember
You have practiced Go Workspaces in a small, self-contained program. The important habit is to predict what runs, inspect the actual output and distinguish the language rule from the particular example.
Before continuing, make sure you can explain the program to someone who has not seen it, including the line that changes its result.
Reaching the recap and completing the quizzes are separate milestones.