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.

051 Versions, minimal version selection and go.sum semantic versions, minimal version selection, go get and the hashes in go.sum Open 052 Workspaces and replace directives go.work, two modules side by side, a replace directive and when to commit a workspace Open 053 Build tags and file suffixes //go:build, a file per platform, the _linux suffix and a build that selects one file Open 054 embed: files inside the binary //go:embed, an embed.FS, a template read from the binary and the size it adds Open 055 Cross-compiling GOOS and GOARCH, go tool dist list, a Windows binary built on Linux and what cgo blocks Open 056 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 057 unsafe.Pointer and its rules unsafe.Sizeof, Pointer conversions, the rules that keep them valid and where the compiler stops checking Open 058 Linker flags and build metadata -ldflags -X, a version stamped at build time, debug.ReadBuildInfo and a reproducible build Open 059 Binary size and startup time what a hello binary contains, size and nm, -s -w and a measurement of the startup Open 060 Project layout cmd, internal, pkg, the package that owns main and a layout that keeps the API small Open 061 CI for a Go project a GitHub Actions job, the module cache, go vet, go test -race and a failing build Open 062 Releasing a Go program tags, goreleaser in words, the archive per platform and a checksum file Open

Lessons