Go Code Review
Structured code review process for Go. Reviews should be constructive, specific,
and cite the relevant principle behind each finding.
Review Process
Execute these steps in order. For each finding, classify severity:
- 🔴 BLOCKER — Must fix before merge. Correctness, data loss, security.
- 🟡 WARNING — Should fix. Maintainability, idiomatic Go, clarity.
- 🟢 SUGGESTION — Consider improving. Style, naming, documentation.
1. Correctness & Safety
Error Handling
- Every error is checked. No blank identifier
_ discarding errors silently.
- Errors are wrapped with context:
fmt.Errorf("fetch user %d: %w", id, err).
- Error values compared with
errors.Is() / errors.As(), never ==.
- No
panic outside of init() or truly unrecoverable situations.
- Errors handled exactly once — no log-and-return patterns.
Nil Safety
- Pointer receivers checked before dereference when nil is a valid state.
- Map reads guarded or use comma-ok idiom.
- Channel operations consider closed/nil channels.
- Slice operations check bounds where relevant.
Concurrency
- Shared mutable state protected by
sync.Mutex or channels.
- No goroutine leaks — every goroutine has a clear termination path.
- Context propagation: all blocking calls accept and respect
context.Context.
sync.WaitGroup or errgroup.Group used for goroutine lifecycle.
2. API Design
- Exported functions have doc comments starting with the function name.
- Accept interfaces, return concrete types.
- Use functional options (
WithTimeout(d)) over config structs for optional params.
- Context is always the first parameter:
func Foo(ctx context.Context, ...).
- Return
error as the last return value.
- Avoid
bool parameters — prefer named types or options.
3. Idiomatic Go
- Uses
:= for local variables, var for zero-value intent.
- No unnecessary
else after return/continue/break.
- Guard clauses and early returns reduce nesting.
defer used for cleanup, placed right after resource acquisition.
range used over manual index iteration where appropriate.
- Struct literals use field names.
- Interfaces defined at consumer, not producer.
4. Package Structure
- Package names are short, lowercase, singular nouns.
- No circular dependencies between packages.
internal/ used for non-public packages.
cmd/ contains main packages, one per binary.
- Clear separation of concerns — no god packages.
5. Testing
- Test functions follow
TestXxx naming convention.
- Table-driven tests used for multiple input/output combinations.
- Test helpers use
t.Helper() for clean stack traces.
- No test logic in
init() — use TestMain when needed.
- Tests use
testify/assert or testify/require consistently, or stdlib only.
- Edge cases covered: empty input, nil, zero values, max values.
t.Parallel() used where safe.
6. Documentation
- All exported types, functions, and constants have doc comments.
- Doc comments start with the name of the entity.
- Package-level doc comment in
doc.go for non-trivial packages.
- Complex algorithms or business logic have inline comments explaining why.
7. Dependencies
go.mod has no replace directives in committed code (except monorepos).
- No unused dependencies.
- Dependencies are from well-maintained, reputable sources.
- Indirect dependencies are understood and acceptable.
Review Output Format
## Code Review Summary
**Files reviewed:** <list>
**Overall assessment:** APPROVE | REQUEST CHANGES | COMMENT
### Findings
#### 🔴 BLOCKER: <title>
- **File:** `path/to/file.go:42`
- **Issue:** <what is wrong>
- **Why:** <which principle or guideline>
- **Fix:** <concrete suggestion>
#### 🟡 WARNING: <title>
...
#### 🟢 SUGGESTION: <title>
...
### What's Done Well
<genuine positive observations — always include at least one>
1---
2name: go-code-review
3description: >
4 Comprehensive code review checklist for Go projects. Evaluates code quality,
5 idiomatic patterns, error handling, naming, package structure, and test coverage.
6 Use when reviewing Go code, PRs, or before merging changes.
7 Trigger examples: "review this code", "check this PR", "code review", "review Go file".
8 Do NOT use for security-specific audits (use go-security-audit) or
9 performance-specific analysis (use go-performance-review).
10metadata:
11 source: https://skillmd.com/skills/aibot88/go-code-review
12---
13
14# Go Code Review
15
16Structured code review process for Go. Reviews should be constructive, specific,
17and cite the relevant principle behind each finding.
18
19## Review Process
20
21Execute these steps in order. For each finding, classify severity:
22- 🔴 **BLOCKER** — Must fix before merge. Correctness, data loss, security.
23- 🟡 **WARNING** — Should fix. Maintainability, idiomatic Go, clarity.
24- 🟢 **SUGGESTION** — Consider improving. Style, naming, documentation.
25
26## 1. Correctness & Safety
27
28### Error Handling
29- Every error is checked. No blank identifier `_` discarding errors silently.
30- Errors are wrapped with context: `fmt.Errorf("fetch user %d: %w", id, err)`.
31- Error values compared with `errors.Is()` / `errors.As()`, never `==`.
32- No `panic` outside of `init()` or truly unrecoverable situations.
33- Errors handled exactly once — no log-and-return patterns.
34
35### Nil Safety
36- Pointer receivers checked before dereference when nil is a valid state.
37- Map reads guarded or use comma-ok idiom.
38- Channel operations consider closed/nil channels.
39- Slice operations check bounds where relevant.
40
41### Concurrency
42- Shared mutable state protected by `sync.Mutex` or channels.
43- No goroutine leaks — every goroutine has a clear termination path.
44- Context propagation: all blocking calls accept and respect `context.Context`.
45- `sync.WaitGroup` or `errgroup.Group` used for goroutine lifecycle.
46
47## 2. API Design
48
49- Exported functions have doc comments starting with the function name.
50- Accept interfaces, return concrete types.
51- Use functional options (`WithTimeout(d)`) over config structs for optional params.
52- Context is always the first parameter: `func Foo(ctx context.Context, ...)`.
53- Return `error` as the last return value.
54- Avoid `bool` parameters — prefer named types or options.
55
56## 3. Idiomatic Go
57
58- Uses `:=` for local variables, `var` for zero-value intent.
59- No unnecessary `else` after return/continue/break.
60- Guard clauses and early returns reduce nesting.
61- `defer` used for cleanup, placed right after resource acquisition.
62- `range` used over manual index iteration where appropriate.
63- Struct literals use field names.
64- Interfaces defined at consumer, not producer.
65
66## 4. Package Structure
67
68- Package names are short, lowercase, singular nouns.
69- No circular dependencies between packages.
70- `internal/` used for non-public packages.
71- `cmd/` contains main packages, one per binary.
72- Clear separation of concerns — no god packages.
73
74## 5. Testing
75
76- Test functions follow `TestXxx` naming convention.
77- Table-driven tests used for multiple input/output combinations.
78- Test helpers use `t.Helper()` for clean stack traces.
79- No test logic in `init()` — use `TestMain` when needed.
80- Tests use `testify/assert` or `testify/require` consistently, or stdlib only.
81- Edge cases covered: empty input, nil, zero values, max values.
82- `t.Parallel()` used where safe.
83
84## 6. Documentation
85
86- All exported types, functions, and constants have doc comments.
87- Doc comments start with the name of the entity.
88- Package-level doc comment in `doc.go` for non-trivial packages.
89- Complex algorithms or business logic have inline comments explaining *why*.
90
91## 7. Dependencies
92
93- `go.mod` has no replace directives in committed code (except monorepos).
94- No unused dependencies.
95- Dependencies are from well-maintained, reputable sources.
96- Indirect dependencies are understood and acceptable.
97
98## Review Output Format
99
100```
101## Code Review Summary
102
103**Files reviewed:** <list>
104**Overall assessment:** APPROVE | REQUEST CHANGES | COMMENT
105
106### Findings
107
108#### 🔴 BLOCKER: <title>
109- **File:** `path/to/file.go:42`
110- **Issue:** <what is wrong>
111- **Why:** <which principle or guideline>
112- **Fix:** <concrete suggestion>
113
114#### 🟡 WARNING: <title>
115...
116
117#### 🟢 SUGGESTION: <title>
118...
119
120### What's Done Well
121<genuine positive observations — always include at least one>
122```