Toolchain and CI
| gofmt -l in CI | |
| vet before merge | |
| go mod tidy | |
| A minimal CI script |
gofmt -l in CI
Go ships one official format, so teams never debate tabs against spaces. The gofmt tool rewrites files into that format, and the l flag lists files that still need formatting without touching them.
The session below finds one unformatted file, fixes it in place with the w flag, and confirms that the second listing stays silent. Silence means every file is clean.
gofmt -l .
main.go
gofmt -w main.go
gofmt -l .
(no output: every file is clean)
vet before merge
The vet tool hunts suspicious code that still compiles. It checks print format strings against arguments, flags unreachable code, and spots common mistakes with locks, shifts, and struct tags.
Run vet over the whole module before every merge. An empty result means vet is happy, while any report deserves a fix rather than a suppression comment.
go vet ./...
(no output: vet is happy)
go mod tidy
The go.mod file lists module dependencies, and real code drifts away from it over time. The tidy command adds missing requirements, drops unused ones, and keeps go.sum in sync.
Run tidy after adding or removing imports, then build the whole module. Both commands stay silent on success, which is exactly the result a clean tree should produce.
go mod tidy
(no output: go.mod and go.sum are in sync)
go build ./...
(no output: the build passes)
A minimal CI script
Continuous integration repeats the same checks on every push that developers run locally. The workflow below installs Go, then runs format, vet, and tests in the same order as this lesson.
Keep the script short at first and extend it later with lint, benchmarks, or release jobs. A short script that always runs beats a grand pipeline that stays disabled.
cat .github/workflows/go.yml
name: go
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: gofmt -l .
- run: go vet ./...
- run: go test ./...
go test ./...
ok wordfreq 0.012s
Next: Project layout
Article author: Arthur Isaev