Claude-skill-registry golang-best-practices
Comprehensive Go code review meta-skill. Coordinates 5 specialized domain skills. For targeted reviews, use domain-specific skills (concurrency-safety, clean-architecture). For full audits, use this meta-skill.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/golang-best-practices-skill" ~/.claude/skills/majiayu000-claude-skill-registry-golang-best-practices && rm -rf "$T"
skills/data/golang-best-practices-skill/SKILL.mdGolang Best Practices (Meta-Skill)
Comprehensive Go code review skill coordinating 5 specialized domain skills for complete code audits.
[!NOTE] v2.0.0 Update: This skill now coordinates multiple focused domain skills. Use specific skills for targeted reviews or this meta-skill for comprehensive audits.
Available Skills
1. Concurrency Safety ✅
12 rules | Goroutines, channels, race conditions, deadlocks
Status: Active (v2.0.0)
Use when:
- Reviewing code with goroutines or channels
- Debugging race conditions or deadlocks
- Auditing concurrent data access
Trigger phrases: "Check for race conditions", "Review concurrency", "Find goroutine leaks"
2. Clean Architecture ✅
9 rules | Layer separation, dependency rules, gRPC patterns
Status: Active (v2.0.0)
Use when:
- Auditing service architecture
- Reviewing layered architecture compliance
- Ensuring proper dependency injection
Trigger phrases: "Audit architecture", "Check layer dependencies", "Review Clean Architecture"
3. Error Handling ✅
7 rules | Error wrapping, context, nil checks
Status: Active (v2.0.0)
Use when:
- Reviewing error propagation
- Checking context usage
- Auditing error handling patterns
Trigger phrases: "Review error handling", "Check error wrapping", "Verify context propagation"
4. Design Patterns ✅
13 rules | Code smells, refactoring, Gang of Four patterns
Status: Active (v2.0.0)
Use when:
- Refactoring complex code
- Reducing technical debt
- Applying design patterns
Trigger phrases: "Refactor this code", "Reduce complexity", "Apply design patterns"
5. Idiomatic Go ✅
6 rules | Go-specific idioms, interfaces, pointers
Status: Active (v2.0.0)
Use when:
- Ensuring idiomatic Go style
- Reviewing interface usage
- Optimizing pointer usage
Trigger phrases: "Is this idiomatic Go?", "Review Go style", "Check interface design"
When to Use This Meta-Skill
Use this meta-skill for:
- Complete codebase audits
- Pre-production reviews
- Unknown issue categories
- Comprehensive refactoring
For targeted reviews, use specific skills above (e.g., just concurrency-safety or clean-architecture).
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rule Count |
|---|---|---|---|---|
| 1 | Critical Issues | CRITICAL | | 8 |
| 2 | High-Impact Patterns | HIGH | | 14 |
| 3 | Medium Improvements | MEDIUM | | 21 |
| 4 | Architecture | ARCHITECTURE | | 5 |
Quick Reference
1. Critical Issues (CRITICAL)
These prevent bugs, crashes, and production failures
- Use %w for error wrapping, not %vcritical-error-wrapping
- Avoid defer in loops (resource leaks)critical-defer-in-loop
- Always defer cancel() after context creationcritical-context-leak
- Don't shadow err variable in nested scopescritical-error-shadow
- Goroutines must have exit conditionscritical-goroutine-leak
- Protect shared state with mutex/channelscritical-race-condition
- Ensure paired send/receive operationscritical-channel-deadlock
- Sender closes channel, not receivercritical-close-panic
2. High-Impact Patterns (HIGH)
Reliability and correctness improvements
- Use pointer receivers for mutationshigh-pointer-receiver
- Propagate context through call chainhigh-context-propagation
- Use errors.Is/As instead of ==high-error-is-as
- Check interface nil correctlyhigh-interface-nil
- Limit concurrent goroutines (worker pool)high-goroutine-unbounded
- Always close channels when donehigh-channel-not-closed
- Avoid closure over loop variableshigh-loop-variable-capture
- Match Add() and Done() callshigh-waitgroup-mismatch
- Keep delivery layer thinhigh-business-logic-handler
- No business logic in data layerhigh-business-logic-repository
- Inject dependencies, don't createhigh-constructor-creates-deps
- Transactions belong in usecasehigh-transaction-in-repository
- Extract logic from 300+ line functionshigh-god-object
- Name complex code blocks with descriptive methodshigh-extract-method
3. Medium Improvements (MEDIUM)
Code quality and idioms
- Keep interfaces small (<5 methods)medium-interface-pollution
- API flexibility patternmedium-accept-interface-return-struct
- Don't overuse pointers for small typesmedium-pointer-overuse
- Use send/receive-only channelsmedium-directional-channels
- Choose appropriate buffer sizemedium-buffered-channel-size
- Avoid busy-wait with selectmedium-select-default
- Split large interfacesmedium-fat-interface
- Move business logic to domain entitiesmedium-usecase-complexity
- Define interfaces where usedmedium-interface-in-implementation
- Use sentinel errors for stable categoriesmedium-sentinel-error-usage
- Replace primitives with value objectsmedium-primitive-obsession
- Use parameter objects for >5 paramsmedium-long-parameter-list
- Extract repeated parameter groupsmedium-data-clumps
- Move logic closer to datamedium-feature-envy
- Replace magic numbers with named constantsmedium-magic-constants
- Fluent API for complex constructionmedium-builder-pattern
- Validated object creationmedium-factory-constructor
- Group related parametersmedium-introduce-parameter-object
- Replace type switches with interfacesmedium-switch-to-strategy
- Decorator pattern for http.Handlermedium-middleware-decorator
- Reduce coupling, avoid message chainsmedium-law-of-demeter
4. Architecture (ARCHITECTURE)
Clean Architecture compliance for gRPC/usecase/repository pattern
- Domain must not import infrastructurearch-domain-import-infra
- Depend on interfaces, not concrete typesarch-concrete-dependency
- Repositories do CRUD onlyarch-repository-business-logic
- Usecases orchestrate, entities decidearch-usecase-orchestration
- Small, consumer-defined interfacesarch-interface-segregation
How to Use
For Code Review
- Read the code file(s)
- Check against rules in priority order (Critical first)
- For each violation found, reference the specific rule file
- Provide exact line numbers and explanation
- Show corrected code example
For Refactoring
- Identify code smells matching detection patterns
- Apply fixes from corresponding rule files
- Verify no regressions introduced
- Run tests to confirm correctness
Accessing Detailed Rules
Each rule file contains:
- Brief explanation of why it matters
- Detection criteria (how to spot the issue)
- Incorrect code example with explanation
- Correct code example with explanation
- Impact assessment
- Additional context and references
Example:
rules/critical-error-wrapping.md rules/high-pointer-receiver.md
Reference Guides
For deep dives on specific topics:
- Comprehensive concurrency patternsreferences/concurrency-deep-dive.md
- Complete error handling strategiesreferences/error-handling-guide.md
- Go testing best practicesreferences/testing-strategies.md
Common Usage Patterns
Review entire file:
Review this Go file for anti-patterns and suggest improvements
Focus on specific category:
Check this code for concurrency issues (CRITICAL level)
Architecture audit:
Verify this service follows Clean Architecture principles
Performance optimization:
Find performance issues in this Go code
Trigger Phrases
For comprehensive audits (uses this meta-skill):
- "Review my Go code"
- "Check this Golang file"
- "Find Go anti-patterns"
- "Audit this Go service"
For domain-specific reviews (uses specific skills):
- "Check for race conditions" → concurrency-safety
- "Audit architecture" → clean-architecture
- "Review error handling" → error-handling
- "Refactor this code" → design-patterns
- "Is this idiomatic Go?" → idiomatic-go
Best Practices Philosophy
Based on research from authoritative sources:
Jon Bodner's Principles:
- Go is deliberately simple and explicit
- "Boring" code is good code - predictable and maintainable
- Understand the "why" behind language features
- Idiomatic Go prioritizes clarity over cleverness
Katherine Cox-Buday's Guidelines:
- Concurrency is not parallelism
- Channels are for communication, mutexes are for state
- Always have exit conditions for goroutines
- Context is the standard way to propagate cancellation
Clean Architecture (Uncle Bob):
- Dependencies point inward toward business logic
- Domain layer has no external dependencies
- Interfaces defined by consumers, not producers
- Separation of concerns across layers
Output Format
When reviewing code, use this format:
## Critical Issues Found: X ### [Rule Name] (Line Y) **Issue**: Brief description **Fix**: Suggested correction **Example**: ```go // Corrected code here
Medium Improvements: X
[Similar format for medium priority items]
## Notes - Rules are evidence-based from authoritative Go books - Detection patterns help identify issues programmatically - All rules include working code examples - Tailored for gRPC/usecase/repository architecture patterns