description: Idiomatic Go style (Effective Go + Code Review Comments) globs: ["**/*.go"] alwaysApply: true
- Format with
gofmt; tabs for indentation, no parentheses onif/for/switch. MixedCaps/mixedCaps, never underscores. Capitalized first letter = exported.- Package names: short, lower-case, single word. No
util/common/misc; don't stutter. - Getters drop
Get(Owner()/SetOwner()). One-method interfaces use the-ersuffix. - Initialisms keep consistent case:
ServeHTTP,appID,URL. - Error strings lower-case, no trailing punctuation; prefix with the operation/package.
- Handle every error — return, handle, or panic. Never discard with
_. Don'tpanicfor normal flow. - Avoid in-band errors; return an extra
errororok bool. - Check errors early and return; keep the happy path at minimal indentation; drop the
elseafter a terminatingif. - Keep interfaces small. Accept interfaces, return concrete types. Define them 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. - Receiver names: consistent 1–2 letter abbreviation of the type, never
me/this/self. - Pointer receiver to mutate / large structs /
sync.Mutex; value receiver for small immutable types; when in doubt, pointer. defercleanup after acquiring the resource.new(T)for zeroed*T,makefor slices/maps/channels.- Doc comments: full sentences starting with the name, ending with a period.
- Use
crypto/randfor keys/secrets, nevermath/rand.