Experimenting with golang-1.18 multi-module workspaces
brew install go
$ go version
go version go1.18 darwin/arm64
# run generate first
go generate ./...
# root module
go run ./...
go test -v ./...
go test -v -fuzz=Fuzz ./internal
# lib module
go test -v ./lib/...
# app modules
go run ./cmd/app1/...
go run ./cmd/app2/...
go generate ./...
go build -v .
# check SBOM
go version -m go-workspace
# run binary
./go-workspace
$ go help work
Usage:
go work <command> [arguments]
The commands are:
edit edit go.work from tools or scripts
init initialize workspace file
sync sync workspace build list to modules
use add modules to workspace file
Run go work use -r ./
to recursively add directories in the argument directory with a go.mod file to your workspace.
If a directory doesn’t have a go.mod file, or no longer exists, the use directive for that directory is removed from your go.work file.
# recursively add directories to go.work
go work use -r .
# pushes the dependencies in the go.work file back into the go.mod files of each workspace module.
go work sync
# provides a command-line interface for editing go.work, for use primarily by tools or scripts.
go work edit
# `go mod` examples
go mod download
go mod graph
go mod tidy
go mod verify
go work sync
go mod why -m github.com/ssoroka/slice
.
├── README.md
├── cmd
│ ├── app1
│ │ ├── go.mod
│ │ └── main.go
│ └── app2
│ ├── go.mod
│ └── main.go
├── go.work
├── go.work.sum
└── lib
├── binaryheap
│ ├── binaryheap.go
│ └── binaryheap_test.go
├── filter
│ ├── filter.go
│ └── filter_test.go
└── go.mod