| name | go-backend |
| description | Goバックエンド開発 - Goイディオム、並行処理、エラーハンドリング、テスト |
| requires-guidelines | ["golang","common"] |
| hooks | [{"event":"PreSkillUse","command":"~/.claude/hooks/pre-skill-use.sh"}] |
Goバックエンド開発
使用タイミング
- Go バックエンド実装時
- Go コードレビュー時
- 並行処理・パフォーマンス最適化時
開発観点
🔴 Critical(修正必須)
1. エラーハンドリング違反
result, _ := userRepo.Find(id)
if err != nil {
panic(err)
}
result, err := userRepo.Find(id)
if err != nil {
return fmt.Errorf("failed to find user: %w", err)
}
2. goroutine リーク
func process() {
ch := make(chan int)
go func() {
for v := range ch {
fmt.Println(v)
}
}()
}
func process(ctx context.Context) {
ch := make(chan int)
go func() {
defer close(ch)
for {
select {
case <-ctx.Done():
return
case v := <-ch:
fmt.Println(v)
}
}
}()
}
3. インターフェース濫用
type UserRepositoryInterface interface {
Find(int) (*User, error)
Save(*User) error
}
type UserRepository interface {
Find(int) (*User, error)
}
type userRepositoryImpl struct { ... }
func (r *userRepositoryImpl) Find(id int) (*User, error) { ... }
🟡 Warning(要改善)
1. context 不使用
func FetchData(url string) ([]byte, error) {
resp, err := http.Get(url)
...
}
func FetchData(ctx context.Context, url string) ([]byte, error) {
req, _ := http.NewRequestWithContext(ctx, "GET", url, nil)
resp, err := http.DefaultClient.Do(req)
...
}
2. sync.Mutex の defer 忘れ
mu.Lock()
if err := process(); err != nil {
return err
}
mu.Unlock()
mu.Lock()
defer mu.Unlock()
if err := process(); err != nil {
return err
}
3. テーブル駆動テスト未使用
func TestAdd(t *testing.T) {
if Add(1, 2) != 3 { t.Error("failed") }
if Add(0, 0) != 0 { t.Error("failed") }
}
func TestAdd(t *testing.T) {
tests := []struct {
name string
a, b int
want int
}{
{"positive", 1, 2, 3},
{"zero", 0, 0, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Add(tt.a, tt.b); got != tt.want {
t.Errorf("got %d, want %d", got, tt.want)
}
})
}
}
Go イディオムチェック
命名規則
エラーハンドリング
並行処理
設計
テストチェックリスト
出力形式
🔴 Critical: ファイル:行 - エラー処理違反/goroutineリーク - 修正案
🟡 Warning: ファイル:行 - イディオム違反 - 改善案
📊 Summary: Critical X件 / Warning Y件
関連ガイドライン
開発実施前に以下のガイドラインを参照:
~/.claude/guidelines/languages/golang.md
~/.claude/guidelines/common/code-quality-design.md
~/.claude/guidelines/common/testing-guidelines.md
外部知識ベース
最新のGoベストプラクティス確認には context7 を活用:
- Go公式ドキュメント(Effective Go)
- Go標準ライブラリ(net/http, context, sync)
- Go Concurrency Patterns
プロジェクトコンテキスト
プロジェクト固有のGo実装情報を確認:
- serena memory からディレクトリ構成・命名規則を取得
- プロジェクトの標準的なエラーハンドリングパターンを優先
- 既存の並行処理パターンとの一貫性を確認