Instruction file imported from lukasz-lobocki/step-badger (
.github/instructions/go.instructions.md). Copyright stays with the author.
Go source conventions
- Group imports in three blocks: stdlib, third-party, local.
goimportsordering. - Prefer early returns over nested
if/else; keep the happy path left-aligned. - Name receivers consistently and briefly (
func (s *Server)), neverself/this. - Use
anyoverinterface{}(Go 1.18+). - Slices: preallocate with
make([]T, 0, n)whennis known. - Strings: use
strings.Builderfor concatenation in loops. - Avoid naked returns except in very short functions.
- Struct literals must use field names.
- Guard
nilmaps before write; reads ofnilmaps are fine. deferfor cleanup; check the error of deferredClose()when it matters (writers, transactions) via a named return.- Time: always
time.Duration, never bare ints. Usetime.Since. - Prefer
log/slogfor structured logging; nofmt.Printlnin production paths.