anti-patterns.mdMarkdown, rendered
Common Go Anti-Patterns
Error handling
Avoid:
- Comparing errors by message text
- Dropping context when returning errors
Prefer:
fmt.Errorf("...: %w", err)errors.Is/errors.As
Concurrency
Avoid:
- Fire-and-forget goroutines in request paths
- Goroutines blocked forever on channels with no cancellation path
sync.WaitGroup.Addinside goroutines
Prefer:
- Context-aware goroutines with explicit shutdown/cancel logic
- Structured fan-out/fan-in patterns with lifecycle ownership
SQL and input handling
Avoid:
- SQL built with string formatting/concatenation
Prefer:
- Parameterized queries/placeholders
Testing and CI
Avoid:
- Relying only on
go testfor concurrent systems - No vet/static checks in CI
Prefer:
go test,go vet,go test -race, and fuzz workflows where relevant
Performance
Avoid:
- Micro-optimizing without benchmark/profile evidence
Prefer:
- Benchmark +
pprofdriven optimization plans
Observability
Avoid:
- Unstructured logs for complex services
Prefer:
- Structured logs with stable fields (
log/slogstyle)