The core Go toolchain already covers most of the build, test and release workflow: go mod for dependencies, go build for binaries, go test for tests and benchmarks, go vet and gofmt for correctness and style, and pprof for profiling. Add golangci-lint for deeper static analysis, Docker for packaging, and log/slog plus Prometheus for observability.
This guide groups the tools by stage and ends with practices that keep a Go project reproducible and easy to ship.
Go modules are the standard dependency system. A module is described by go.mod, and checksums are recorded in go.sum. Commit both files.
go mod tidy adds missing and removes unused requirements.go list -m -u all lists available upgrades.go mod vendor copies dependencies into vendor/ if you need offline or locked builds.go and toolchain lines in go.mod pin the Go version; since Go 1.21 the go command can download the required toolchain automatically.govulncheck ./... (from golang.org/x/vuln) to find known vulnerabilities in code you actually call.Pin versions rather than floating on latest in production code, and review upgrades like any other change.
go build compiles a package into a single statically linked binary by default when cgo is not needed.
| Flag | Purpose |
|---|---|
-trimpath | Remove local file paths from the binary for reproducible builds |
-ldflags="-s -w" | Strip symbol and debug tables to shrink the binary |
-X main.version=... | Inject a version string at link time |
-race | Build with the data race detector (tests and staging only) |
go run, go install and go generate round out the build tools. Use go generate for code generation such as mocks or stringers.
Run these on every commit, locally and in CI.
A minimal table-driven test:
Go also ships fuzzing (go test -fuzz) and benchmarks. For assertions and mocks, testify is common but optional. golangci-lint is a third-party aggregator; configure it in .golangci.yml and keep the enabled linters small enough that the team respects the output. Use gofmt or goimports through your editor so formatting never appears in code review.
dlv debug, dlv test, dlv attach) is the standard debugger and is used by VS Code and GoLand.go tool pprof analyses CPU, heap and goroutine profiles; expose net/http/pprof only on an internal port.go tool trace visualises scheduler and GC activity captured with runtime/trace.go build -gcflags=-m shows escape analysis and inlining decisions.A multi-stage Dockerfile keeps images small and builds reproducible:
Copying go.mod first lets Docker cache downloaded modules. For Kubernetes, expose liveness and readiness endpoints, handle SIGTERM with http.Server.Shutdown, and set GOMEMLIMIT to match the container limit.
For observability, use the standard log/slog package for structured logs, the Prometheus client (prometheus/client_golang) for metrics, and OpenTelemetry for traces:
CI systems such as GitHub Actions run the same commands as above, so a pipeline is usually go vet, golangci-lint, go test -race, govulncheck, then build and push an image.
cmd/ and private code under internal/.go.mod and go.sum, and run go mod tidy in CI to catch drift.context.Context as the first argument through request paths and honour cancellation.fmt.Errorf("...: %w", err) and check them with errors.Is and errors.As.govulncheck and keep the Go toolchain on a supported release.Usually not. go build, go test and a short Makefile or CI script are enough. Tools like GoReleaser help when you publish binaries for many platforms.
golangci-lint part of Go?No. It is a separate open-source project that runs many linters. go vet and gofmt are the built-in checks.
Build with CGO_ENABLED=0 in a builder stage and copy the binary to a minimal base such as distroless or scratch. Add CA certificates if the program makes HTTPS calls.
The Go project supports the two most recent major releases with security fixes. Check go.dev/doc/devel/release for the current list before choosing a base image.
Lean on the standard toolchain for modules, builds, tests, vetting and profiling, add golangci-lint and govulncheck for extra safety, package with a multi-stage Docker build, and instrument services with slog, Prometheus and OpenTelemetry. Automate the same commands in CI so every build is repeatable.