GuideOpen
Go - Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only Go-specific rules and idioms.
Front matter
language: go
extensions: [".go"]Go — Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only Go-specific rules and idioms.
PR Analyzer — Go Risk Signals
fmt.Println/log.Printlndebug statements left in production code//nolintcomments — verify they are justifiedunsafepackage imports — require explicit sign-off- Hardcoded credentials or tokens in source
Code Quality — Go Checks
- Errors returned but not checked (
_ = someFunc()) panic()used outside of package initialization- Goroutines started without a clear lifetime or cancellation path
interface{}/anyused where a concrete type or typed interface would work- Missing context propagation (
context.Contextnot threaded through call chains)
Security
- Flag
database/sqlqueries built withfmt.Sprintf— require?/$Nplaceholders - Flag
os/execcalls with user-controlled arguments without sanitization - Flag
html/templatebypassed in favor oftext/templatefor HTML output - Flag
http.ListenAndServeTLSwithInsecureSkipVerify: true
Async / Concurrency
- Flag goroutines started with no clear lifetime or cancellation path — always pass
context.Context - Flag goroutines that write to a channel with no receiver and no
selectdefault — causes a leak - Flag
time.Sleep()used inside a goroutine as a synchronization mechanism - Flag
sync.WaitGroup.Add()called inside the goroutine it tracks — race condition - Flag
sync.Mutexcopied by value — must always be used as a pointer or embedded in a struct
Resource Management
- Flag
http.Response.Bodynot closed after reading — even on error paths (defer resp.Body.Close()) - Flag
os.Filenot closed — usedefer f.Close()immediately after opening - Flag
rows.Close()missing aftersql.Query()— leaks the DB connection - Flag
context.WithCancel/context.WithTimeoutcancel function not called — context and resources leak
Exception Handling
- Flag errors assigned to
_without a comment explaining why it is safe to ignore - Flag errors not wrapped with
fmt.Errorf("...: %w", err)— loses stack context - Flag
errors.New/fmt.Errorfstrings starting with a capital letter or ending in punctuation — violates Go conventions - Flag
panic()used for expected runtime errors — reserve for programming errors and unrecoverable states - Flag
recover()used to silently swallow panics without logging
Performance
- Flag
fmt.Sprintfused for simple string concatenation — usestrings.Builderor+for small cases - Flag
append()in a tight loop without pre-allocating slice capacity — usemake([]T, 0, n) - Flag
json.Marshal/json.Unmarshalon large structs in hot paths — considerjson.Encoder/ streaming - Flag goroutines spawned per-request without a worker pool for CPU-bound tasks
Idioms and Best Practices
Error Handling
- All returned errors must be checked — never assign to
_without a comment - Prefer wrapping with
fmt.Errorf("...: %w", err)for stack context - Use
errors.Is/errors.Asfor error inspection — never string comparison
Concurrency
- Every goroutine must have an owner responsible for its lifetime
- Always pass
context.Contextas the first argument to functions that do I/O or block - Prefer
sync.WaitGrouporerrgroupover ad-hoc channel coordination
Modern Go (1.18+)
- Prefer generics over
interface{}for container types and utility functions - Use
any(alias forinterface{}) in new code for readability
Author: alirezarezvani, Alireza Rezvani skills and agents. License: MIT.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
There are more like this in the members library
The Codex library holds 7,009 entries. Members can search all of them by meaning and read every one in full.