golang-base-practices
1
总安装量
1
周安装量
#53557
全站排名
安装命令
npx skills add https://github.com/cexll/golang-base-practices-skills --skill golang-base-practices
Agent 安装分布
amp
1
trae
1
trae-cn
1
kimi-cli
1
codex
1
Skill 文档
Golang 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