go-code-review
27
总安装量
27
周安装量
#7557
全站排名
安装命令
npx skills add https://github.com/cxuu/golang-skills --skill go-code-review
Agent 安装分布
codex
20
github-copilot
19
opencode
19
gemini-cli
17
claude-code
16
amp
15
Skill 文档
Go Code Review Checklist
Based on Go Wiki CodeReviewComments. This checklist provides quick review points with references to detailed skills.
Formatting
- gofmt: Code is formatted with
gofmtorgoimportsâ go-linting
Documentation
- Comment sentences: Comments are full sentences starting with the name being described, ending with a period â go-documentation
- Doc comments: All exported names have doc comments; non-trivial unexported declarations too â go-documentation
- Package comments: Package comment appears adjacent to package clause with no blank line â go-documentation
- Named result parameters: Only used when they clarify meaning (e.g., multiple same-type returns), not just to enable naked returns â go-documentation
Error Handling
- Handle errors: No discarded errors with
_; handle, return, or (exceptionally) panic â go-error-handling - Error strings: Lowercase, no punctuation (unless starting with proper noun/acronym) â go-error-handling
- In-band errors: No magic values (-1, “”, nil); use multiple returns with error or ok bool â go-error-handling
- Indent error flow: Handle errors first and return; keep normal path at minimal indentation â go-error-handling
Naming
- MixedCaps: Use
MixedCapsormixedCaps, never underscores; unexported ismaxLengthnotMAX_LENGTHâ go-naming - Initialisms: Keep consistent case:
URL/url,ID/id,HTTP/http(e.g.,ServeHTTP,xmlHTTPRequest) â go-naming - Variable names: Short names for limited scope (
i,r,c); longer names for wider scope â go-naming - Receiver names: One or two letter abbreviation of type (
cforClient); nothis,self,me; consistent across methods â go-naming - Package names: No stuttering (use
chubby.Filenotchubby.ChubbyFile); avoidutil,common,miscâ go-packages
Concurrency
- Goroutine lifetimes: Clear when/whether goroutines exit; document if not obvious â go-concurrency
- Synchronous functions: Prefer sync over async; let callers add concurrency if needed â go-concurrency
- Contexts: First parameter; not in structs; no custom Context types; pass even if you think you don’t need to â go-context
Interfaces
- Interface location: Define in consumer package, not implementor; return concrete types from producers â go-interfaces
- No premature interfaces: Don’t define before used; don’t define “for mocking” on implementor side â go-interfaces
- Receiver type: Use pointer if mutating, has sync fields, or is large; value for small immutable types; don’t mix â go-interfaces
Data Structures
- Empty slices: Prefer
var t []string(nil) overt := []string{}(non-nil zero-length) â go-data-structures - Copying: Be careful copying structs with pointer/slice fields; don’t copy
*Tmethods’ receivers by value â go-data-structures
Security
- Crypto rand: Use
crypto/randfor keys, notmath/randâ go-defensive - Don’t panic: Use error returns for normal error handling; panic only for truly exceptional cases â go-defensive
Style
- Line length: No rigid limit, but avoid uncomfortably long lines; break by semantics, not arbitrary length â go-style-core
- Naked returns: Only in short functions; explicit returns in medium/large functions â go-style-core
- Pass values: Don’t use pointers just to save bytes; pass
stringnot*stringfor small fixed-size types â go-performance
Imports
- Import groups: Standard library first, then blank line, then external packages â go-packages
- Import renaming: Avoid unless collision; rename local/project-specific import on collision â go-packages
- Import blank:
import _ "pkg"only in main package or tests â go-packages - Import dot: Only for circular dependency workarounds in tests â go-packages
Testing
- Examples: Include runnable
Examplefunctions or tests demonstrating usage â go-documentation - Useful test failures: Messages include what was wrong, inputs, got, and want; order is
got != wantâ go-testing
Quick Review Commands
# Format and organize imports
goimports -w .
# Run linter suite
golangci-lint run
# Check for common issues
go vet ./...
See Also
- go-linting: Automated tooling for style enforcement
- go-style-core: Core Go style principles
- go-documentation: Documentation and comment standards
- go-error-handling: Error handling patterns
- go-naming: Naming conventions
- go-packages: Package design and imports
- go-interfaces: Interface design patterns
- go-concurrency: Concurrency patterns
- go-context: Context usage patterns
- go-data-structures: Data structure idioms
- go-defensive: Defensive programming
- go-testing: Testing patterns
- go-performance: Performance considerations