Best practices
Habits experienced Go teams agree on.
gofmt and go vet always
Formatting is not a debate in Go. Add staticcheck or golangci-lint in CI.
Accept interfaces, return structs
Define interfaces where they are consumed, keep them small (io.Reader has one method).
context.Context as first parameter
Propagate cancellation and deadlines through every I/O call.
Wrap errors with context
fmt.Errorf("doing X: %w", err) and inspect with errors.Is / errors.As.
Run tests with -race
The race detector finds data races that tests alone miss.
Saved in this browser only. Part of Clean code foundations (0/5).