About golang-base-practices
A Go development guide for code generation, reviews, and refactoring. Its 53 priority-ranked rules include examples and references to established Go style guides.
Key features
- 0153 priority-ranked rules
- 02Framework and database guidance
- 03Error handling and concurrency practices
- 04Testing and performance recommendations
- 05Examples and references
Use cases
- 01Starting Go projects or microservices
- 02Reviewing and refactoring code
- 03Planning database operations and migrations
- 04Improving test coverage and concurrent code
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ cexll/ golang-base-practices-skills --skill golang-base-practicesAfter installing, type/golang-base-practicesin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
README.mdrules/concurrency-sync-primitives.mdconcurrency-channel-size.mddb-goose-migrations.mdconcurrency-goroutine-lifecycle.mdconcurrency-context-cancel.mddb-connection-pool.mdconcurrency-errgroup.mdconcurrency-race-detection.mdconcurrency-channel-patterns.mddb-gorm-transactions.mderror-api-response.mdddd-interface-layer.mdddd-project-layout.mdddd-domain-layer.mddb-gorm-setup.mdddd-infrastructure-layer.mddb-gorm-hooks.mdddd-application-layer.mdddd-dependency-injection.mderror-custom-types.mderror-handling-check.mdframework-gin-simple.mderror-sentinel.mderror-wrap-context.mdframework-kratos-complex.mdframework-middleware.mdidiomatic-blank-identifier.mderror-panic-recover.mdframework-graceful-shutdown.mdDetails
From the project READMEGolang Base Practices
Comprehensive Go development best practices guide, organized by priority for code generation, review, and refactoring. Contains 53 rules referenced from Effective Go, Google Go Style Guide, Uber Go Style Guide, and Go Code Review Comments.
When to Apply
Reference these guidelines when:
- Creating new Go projects or microservices
- Building API interfaces (REST/gRPC)
- Performing database operations and migrations
- Conducting code reviews and refactoring
- Optimizing performance and concurrency
- Improving test coverage
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Framework Selection | CRITICAL | framework- |
| 2 | Database & ORM | CRITICAL | db- |
| 3 | DDD Project Structure | HIGH | ddd- |
| 4 | Error Handling | HIGH | error- |
| 5 | Concurrency Patterns | HIGH | concurrency- |
| 6 | Idiomatic Go | MEDIUM | idiomatic- |
| 7 | Testing Practices | CRITICAL | testing- |
| 8 | Performance Optimization | MEDIUM | performance- |
| 9 | Lint & Toolchain | MEDIUM | lint- |
Quick Reference
1. Framework Selection (CRITICAL)
framework-gin-simple- Use Gin for simple projectsframework-kratos-complex- Use Go-Kratos for complex microservicesframework-middleware- Middleware design patternsframework-graceful-shutdown- Graceful server shutdown
2. Database & ORM (CRITICAL)
db-gorm-setup- GORM initialization and configurationdb-gorm-hooks- GORM Hook usage guidelinesdb-gorm-transactions- Transaction handling patternsdb-goose-migrations- Database migrations with Goosedb-connection-pool- Connection pool configuration
3. DDD Project Structure (HIGH)
ddd-project-layout- Standard project directory structureddd-domain-layer- Domain layer designddd-application-layer- Application layer designddd-infrastructure-layer- Infrastructure layer designddd-interface-layer- Interface layer designddd-dependency-injection- Dependency injection patterns
4. Error Handling (HIGH)
error-wrap-context- Error wrapping with contexterror-sentinel- Sentinel error definitionserror-custom-types- Custom error typeserror-handling-check- Always check error returnserror-api-response- API error response standardserror-panic-recover- Panic and recover usage guidelines
5. Concurrency Patterns (HIGH)
concurrency-goroutine-lifecycle- Goroutine lifecycle managementconcurrency-channel-patterns- Channel usage patternsconcurrency-channel-size- Channel buffer size selectionconcurrency-context-cancel- Context cancellation propagationconcurrency-errgroup- errgroup concurrency controlconcurrency-sync-primitives- sync package primitives usageconcurrency-race-detection- Race condition detection
6. Idiomatic Go (MEDIUM)
idiomatic-naming- Naming conventionsidiomatic-comment- Doc Comments guidelinesidiomatic-interface- Interface design (prefer small interfaces)idiomatic-receiver- Receiver naming and selectionidiomatic-struct-init- Struct initializationidiomatic-functional-options- Functional options patternidiomatic-defer- defer usage guidelinesidiomatic-slice-map- Slice and Map operationsidiomatic-zero-value- Zero value utilizationidiomatic-embedding- Type embeddingidiomatic-blank-identifier- Blank identifier usage
7. Testing Practices (CRITICAL)
testing-coverage-99- 99% test coverage targettesting-table-driven- Table-driven teststesting-mock- Mocking and interface abstractiontesting-helper- Test helper function guidelinestesting-benchmark- Benchmark testingtesting-integration- Integration testing standardstesting-testify- testify assertion library usage
8. Performance Optimization (MEDIUM)
performance-strconv- Use strconv instead of fmtperformance-prealloc- Container preallocation
9. Lint & Toolchain (MEDIUM)
lint-golangci- golangci-lint configurationlint-gofmt- Code formattinglint-govet- Static analysislint-staticcheck- Advanced static checkinglint-revive- Customizable linter
How to Use
Consult specific rule files in the rules/ directory for detailed explanations and code examples:
rules/framework-gin-simple.md
rules/db-gorm-setup.md
rules/testing-table-driven.md
Each rule file contains:
- Rule explanation and importance
- Incorrect example with analysis
- Correct example with explanation
- Additional context and references
Core Principles
- KISS - Keep it simple, avoid over-engineering
- YAGNI - Only implement what is currently needed
- Explicit over Implicit - Code intent should be clear
- Handle All Errors - Never ignore error returns
- 99% Test Coverage - Foundation for high-quality code
Comments
Markdown supported