| name | go-code-review |
| description | Go code review checklist based on official Go style guides. When reviewing Go code for style, idioms, and best practices |
| metadata | {"languages":"go"} |
Go Code Review
Comprehensive code review checklist based on official Go style guides.
Reference URLs
For deeper information, fetch these URLs:
Formatting
Gofmt
Run: gofmt -w . or goimports -w .
Line Length
- No rigid limit, but avoid uncomfortably long lines
- Break lines by semantics, not arbitrary length
- Long lines often indicate need for shorter names or refactoring
Naming
Package Names
Variable Names
Receiver Names
Initialisms
Getters/Setters
Interface Names
Comments
Comment Sentences
type Request struct { ... }
func Encode(w io.Writer, req *Request) { ... }
Package Comments
package math
Error Handling
Handle Errors
Error Strings
Error Flow
if err != nil {
return err
}
if err != nil {
} else {
}
Don't Panic
Context
Concurrency
Goroutine Lifetimes
Synchronous Functions
Race Detection
Interfaces
Interface Location
package consumer
type Thinger interface { Thing() bool }
package producer
type Thinger interface { Thing() bool }
func NewThinger() Thinger { ... }
Return Types
Data Types
Empty Slices
Copying
Pass Values
Crypto Rand
Imports
Import Organization
import (
"fmt"
"os"
"github.com/foo/bar"
)
Import Naming
Import Blank
Import Dot
Testing
Test Failures
if got != tt.want {
t.Errorf("Foo(%q) = %d; want %d", tt.in, got, tt.want)
}
Test Names
Table-Driven Tests
Named Results
func (n *Node) Parent1() (node *Node) {}
func (n *Node) Parent1() *Node {}
func (f *Foo) Location() (lat, long float64, err error)
In-Band Errors
func Lookup(key string) (value string, ok bool)
func Lookup(key string) string
Switch Statements
Direct Evaluation
switch status := getStatus(); status {
case StatusPending:
return "pending"
case StatusActive:
return "active"
case StatusDone:
return "done"
default:
return "unknown"
}
if status := getStatus(); status == StatusPending {
return "pending"
} else if status == StatusActive {
return "active"
} else if status == StatusDone {
return "done"
} else {
return "unknown"
}
Type Switches
var i interface{} = "hello"
switch v := i.(type) {
case string:
fmt.Println("string:", v)
case int:
fmt.Println("int:", v)
default:
fmt.Println("unknown type")
}
Fallthrough
switch kind {
case "admin", "owner", "superadmin":
grantFullAccess()
}
Modern Go Idioms (Go 1.21+)
Standard Library Preferences
slices.Sort(items)
if slices.Contains(items, target) { ... }
clone := maps.Clone(original)
sort.Slice(items, func(i, j int) bool { return items[i] < items[j] })
sort.Ints(items)
for _, item := range items {
if item == target { found = true; break }
}
clone := make(map[K]V, len(original))
for k, v := range original { clone[k] = v }
Generics
Time-Dependent Code
type Clock interface { Now() time.Time }
type Service struct { clock Clock }
func (s *Service) IsExpired() bool {
return time.Now().After(s.expiresAt)
}
Iterators (Go 1.23+)
WaitGroup.Go (Go 1.24+)
var wg sync.WaitGroup
for _, task := range tasks {
wg.Go(func() {
process(task)
})
}
wg.Wait()
var wg sync.WaitGroup
for _, task := range tasks {
wg.Add(1)
go func(t Task) {
defer wg.Done()
process(t)
}(task)
}
wg.Wait()
Dead Code Detection
Bare Blocks
msg := buildFlowMessage()
{
multiModelSection := processMultiModel()
}
msg := buildFlowMessage()
multiModelSection := processMultiModel()
Unused Code
Leftover References
Unreachable Code
func foo() {
return
fmt.Println("this never runs")
}
func foo() {
return
}
Variable Scope
Review Evidence Freshness
Blocking Findings Must Be Revalidated
Quick Checklist
For fast reviews, check these critical items:
- gofmt - Code is formatted
- Errors handled - No ignored errors
- Doc comments - Exports documented
- slices.Delete - Use for slice deletion (not append pattern)
- Naming - Short, idiomatic names
- Tests - Exist and helpful failures
- No panics - Error returns used
- Context - First param when used
- Interfaces - At consumer, not producer
- Modern idioms - Uses slices/maps packages where applicable
- Switch statements - Use switch for multi-way conditionals
- Dead code - No bare blocks, unreachable code, or leftover references
- Evidence freshness - Blocking citations re-opened against current source
Review Output Format
## Code Review: [scope]
### Critical Issues
[Must fix before merge]
### Important Issues
[Should fix]
### Minor Issues
[Nice to have]
### Strengths
[What's done well]
### Verdict: [PASS/NEEDS WORK]
Go References for Idomatic Code