Go ships most of what you need to automate development and deployment inside the go command itself: go build, go test, go vet, go mod, go fmt, go generate and go run. Add staticcheck or golangci-lint for deeper analysis, a multi-stage Docker build for packaging, and a CI workflow that runs the same commands on every push.
Because every step is a plain command with a predictable exit code, the same script works on a laptop and in any CI system.
The core loop is go build, go test and go run. All three understand the package pattern ./..., which means "this module and every package below it".
-trimpath removes local file system paths from the binary, which makes builds reproducible across machines. -ldflags="-s -w" strips the symbol table and debug information to shrink the binary. Cross-compiling needs only environment variables:
Go caches build and test results, so unchanged packages are not rebuilt or re-tested. Use go test -count=1 ./... when you need to bypass the test cache.
Modules are the standard dependency system. go.mod records the module path, the Go version and required modules, and go.sum records checksums.
| Command | What it does |
|---|---|
go mod init example.com/app | Creates go.mod for a new module |
go mod tidy | Adds missing and removes unused requirements |
go get example.com/[email protected] | Adds or upgrades one dependency |
go list -m -u all | Lists modules that have newer versions |
go mod verify | Checks cached modules against go.sum |
go mod vendor | Copies dependencies into a vendor directory |
A useful CI check is to run go mod tidy and fail if it changes anything, which catches forgotten dependency updates:
Go also ships govulncheck, an official tool that reports known vulnerabilities only in code paths your program actually calls:
Formatting is not a style debate in Go. gofmt (also available as go fmt) produces one canonical layout, so a diff never contains formatting noise.
go vet finds suspicious constructs such as wrong Printf verbs, copied locks and unreachable code. For more rules, use staticcheck or the aggregator golangci-lint. The old golint tool is deprecated and frozen, so do not add it to new pipelines.
go generate runs commands that you declare in comments inside the source. It is for code generation steps you run on demand, not on every build.
Running go generate ./... executes stringer and writes a status_string.go file that you commit. Since Go 1.24 you can also declare developer tools in go.mod with a tool directive (go get -tool ...) and run them with go tool <name>, which pins tool versions the same way as libraries.
A Go program compiles to a single static binary, so container images can be tiny. A multi-stage Dockerfile keeps the compiler out of the final image:
Copying go.mod and go.sum first lets Docker cache the dependency download layer until the dependencies change. From there, a Kubernetes Deployment or any container platform provides rolling updates, health checks and scaling.
This GitHub Actions workflow runs the same commands you run locally:
go-version-file: go.mod keeps CI on the same Go version the module declares. Add a separate job for govulncheck and for image builds on tagged releases.
Not required. The go command covers build, test and dependency work, but a small Makefile or Taskfile is common to give the team short names like make lint for several commands.
No. golint was deprecated and frozen. Use go vet plus staticcheck, or golangci-lint, which bundles many linters behind one configuration file.
Pin dependencies with go.mod and go.sum, build with -trimpath, set CGO_ENABLED=0 when you do not need cgo, and use the same Go version in CI and locally.
Set GOOS and GOARCH before go build. Go cross-compiles without extra toolchains when cgo is disabled.
Go's tooling covers the full lifecycle with plain commands: go build and go test for correctness, go mod and govulncheck for dependencies, gofmt, go vet and staticcheck for quality, go generate for code generation, and a multi-stage Docker build for deployment. Run the same commands in CI that you run locally, and your pipeline stays simple and reproducible.