Modules, build and tooling
A module is the unit of a build and of a version. These lessons cover semantic versions and minimal version selection, workspaces, build tags, embed, cross-compiling, cgo and unsafe, and the linker flags that stamp a version into the binary. They measure the size and the startup time that follow from those choices, and end on project layout, CI and a release.
5.1
Versions, minimal version selection and go.sum
semantic versions, minimal version selection, go get and the hashes in go.sum
Open
5.2
Workspaces and replace directives
go.work, two modules side by side, a replace directive and when to commit a workspace
Open
5.3
Build tags and file suffixes
//go:build, a file per platform, the _linux suffix and a build that selects one file
Open
5.4
embed: files inside the binary
//go:embed, an embed.FS, a template read from the binary and the size it adds
Open
5.5
Cross-compiling
GOOS and GOARCH, go tool dist list, a Windows binary built on Linux and what cgo blocks
Open
5.6
cgo: C from Go and the cost of it
import "C", a C function called from Go, the C toolchain and the binary that is no longer static
Open
5.7
unsafe.Pointer and its rules
unsafe.Sizeof, Pointer conversions, the rules that keep them valid and where the compiler stops checking
Open
5.8
Linker flags and build metadata
-ldflags -X, a version stamped at build time, debug.ReadBuildInfo and a reproducible build
Open
5.9
Binary size and startup time
what a hello binary contains, size and nm, -s -w and a measurement of the startup
Open
5.10
Project layout
cmd, internal, pkg, the package that owns main and a layout that keeps the API small
Open
5.11
CI for a Go project
a GitHub Actions job, the module cache, go vet, go test -race and a failing build
Open
5.12
Releasing a Go program
tags, goreleaser in words, the archive per platform and a checksum file
Open