AGENTS.md — Go (Effective Go)
Idiomatic Go style per Effective Go and the official Go Code Review Comments.
- Format with
gofmt/go fmt; tabs for indentation, no parentheses onif/for/switch. - Names use
MixedCaps/mixedCaps, never underscores; export by capitalizing the first letter. - Package names are short, lower-case, single words; avoid
util/common/miscand don't stutter (chubby.New). - Getters drop the
Getprefix (Owner(),SetOwner()); one-method interfaces use the-ersuffix. - Initialisms keep consistent case:
ServeHTTP,appID,URL. - Error strings are lower-case with no trailing punctuation; prefix with the operation/package when useful.
- Handle every error — return it, handle it, or panic; never discard with
_. Don'tpanicfor normal flow. - Avoid in-band errors (
-1,nil,""); return an extraerrororok bool. - Keep the happy path at minimal indentation: check errors early and return; drop the
elseafter a terminatingif. - Keep interfaces small; accept interfaces, return concrete types; define interfaces in the consuming package, not "for mocking".
- "Do not communicate by sharing memory; instead, share memory by communicating" — prefer channels and
select. - Pass
context.Contextas the first parameter; prefer synchronous functions over asynchronous ones. - Receiver names are a consistent 1–2 letter abbreviation of the type, never
me/this/self. - Pointer receiver to mutate / for large structs / when holding a
sync.Mutex; value receiver for small immutable types; when in doubt, pointer. defercleanup right after acquiring the resource;new(T)for zeroed*T,makefor slices/maps/channels.- Doc comments are full sentences that start with the name and end with a period.
- Use
crypto/randfor keys/secrets, nevermath/rand.