← スキル一覧に戻る

golang-backend
by linhdmn
SWE Agent skills
⭐ 0🍴 0📅 2026年1月24日
SKILL.md
name: golang-backend description: Go backend development best practices and performance optimization guidelines. This skill should be used when writing, reviewing, or refactoring Go backend code including APIs, services, concurrent systems, and database interactions. Triggers on tasks involving Go handlers, middleware, goroutines, channels, error handling, or performance improvements. license: MIT metadata: author: freepeak version: "1.0.0"
Go Backend Best Practices
Comprehensive best practices guide for Go backend development, optimized for AI agents and LLMs. Contains 40+ rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Go services, APIs, or handlers
- Implementing concurrent patterns with goroutines and channels
- Reviewing code for performance issues or bugs
- Refactoring existing Go backend code
- Optimizing database queries and connections
- Implementing error handling and logging
- Writing tests for Go code
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Error Handling | CRITICAL | error- |
| 2 | Concurrency Safety | CRITICAL | concurrency- |
| 3 | Performance | HIGH | perf- |
| 4 | API Design | HIGH | api- |
| 5 | Database Patterns | MEDIUM-HIGH | db- |
| 6 | Testing | MEDIUM | test- |
| 7 | Security | CRITICAL | security- |
| 8 | Code Organization | LOW-MEDIUM | org- |
Quick Reference
1. Error Handling (CRITICAL)
error-wrap-context- Wrap errors with context using fmt.Errorf %werror-check-always- Never ignore returned errorserror-sentinel- Use sentinel errors for expected conditionserror-custom-types- Define custom error types for complex errorserror-early-return- Return early on errors, avoid deep nesting
2. Concurrency Safety (CRITICAL)
concurrency-goroutine-leak- Prevent goroutine leaks with context cancellationconcurrency-race-condition- Protect shared state with mutex or channelsconcurrency-channel-close- Only sender should close channelsconcurrency-waitgroup- Use WaitGroup for goroutine synchronizationconcurrency-context-propagation- Propagate context through call chain
3. Performance (HIGH)
perf-preallocate-slices- Preallocate slices when size is knownperf-string-builder- Use strings.Builder for string concatenationperf-sync-pool- Use sync.Pool for frequently allocated objectsperf-avoid-reflection- Avoid reflection in hot pathsperf-buffer-channels- Use buffered channels appropriately
4. API Design (HIGH)
api-accept-interfaces- Accept interfaces, return concrete typesapi-functional-options- Use functional options for configurationapi-context-first- Context should be first parameterapi-naming-conventions- Follow Go naming conventionsapi-package-design- Design packages by responsibility
5. Database Patterns (MEDIUM-HIGH)
db-connection-pool- Configure connection pool properlydb-prepared-statements- Use prepared statements for repeated queriesdb-transaction-scope- Keep transactions short and focuseddb-scan-struct- Use struct scanning for type safetydb-context-timeout- Always use context with timeouts for queries
6. Testing (MEDIUM)
test-table-driven- Use table-driven teststest-parallel- Run independent tests in paralleltest-mock-interfaces- Mock at interface boundariestest-golden-files- Use golden files for complex outputstest-cleanup- Use t.Cleanup for test resource cleanup
7. Security (CRITICAL)
security-sql-injection- Use parameterized queriessecurity-input-validation- Validate and sanitize all inputssecurity-secrets-env- Load secrets from environmentsecurity-rate-limiting- Implement rate limiting for APIssecurity-timeout-config- Configure timeouts for all operations
8. Code Organization (LOW-MEDIUM)
org-flat-structure- Prefer flat package structureorg-internal-packages- Use internal packages for private codeorg-dependency-injection- Use dependency injection for testabilityorg-config-struct- Group configuration in typed structsorg-graceful-shutdown- Implement graceful shutdown
How to Use
Read individual rule files for detailed explanations and code examples:
rules/error-wrap-context.md
rules/concurrency-goroutine-leak.md
rules/_sections.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
スコア
総合スコア
60/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です