Early previewThis guide is in development. Items tagged verify are still being checked against official docs.
nebx Learn
GitHub
Menu
Home/Go/Best practices
Go

Go

Simple, fast to compile, built for concurrent network services.

Paradigm
Procedural, composition over inheritance
Typing
Static, strong, structural interfaces
Memory
Concurrent low-latency GC
Runs
Single static native binary
Concurrency
Goroutines and channels

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).