Guides Go development with best practices from Google Style Guide and Effective Go. Use when go.mod is detected or Go code is being written. Covers naming, error handling, concurrency, testing, and project structure.
Provides Go development guidance following Google Style Guide and Effective Go. Triggers when go.mod is detected or writing Go code. Covers naming, error handling, concurrency, testing, and project structure.
/plugin marketplace add sumik5/sumik-claude-plugin/plugin install sumik@sumikThis skill inherits all available tools. When active, it can use any tool Claude has access to.
CONCURRENCY.mdERROR-HANDLING.mdNAMING.mdPROJECT-STRUCTURE.mdTESTING.mdTOOLING.mdこのスキルは以下のドキュメントで構成されています:
Goの命名ベストプラクティス:
堅牢なエラー処理パターン:
Goの強力な並行処理パターン:
効果的なGoテストの書き方:
推奨ディレクトリレイアウト:
Goエコシステムのツール活用:
// Good: シンプルで明確
func ProcessItems(items []Item) error {
for _, item := range items {
if err := item.Process(); err != nil {
return fmt.Errorf("process item %s: %w", item.ID, err)
}
}
return nil
}
// Bad: 過度な抽象化
func ProcessItems(items []Item, processor ItemProcessor, validator ItemValidator) error {
// 不必要な複雑さ
}
// Good: 明示的なエラーハンドリング
result, err := doSomething()
if err != nil {
return err
}
// Bad: エラーを無視
result, _ := doSomething()
// Good: チャネルで通信
results := make(chan Result)
go func() {
results <- process(data)
}()
result := <-results
// Avoid: 共有メモリでの通信(必要な場合のみ)
var mu sync.Mutex
var shared int
# モジュール作成
mkdir my-project && cd my-project
go mod init github.com/username/my-project
# 基本構造
mkdir -p cmd/myapp internal/handler internal/service
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(),
os.Interrupt, syscall.SIGTERM)
defer cancel()
if err := run(ctx); err != nil {
log.Fatal(err)
}
}
func run(ctx context.Context) error {
// アプリケーションロジック
return nil
}
# フォーマット
gofmt -w .
# Lint
golangci-lint run
# テスト
go test ./...
# ビルド
go build -o bin/myapp ./cmd/myapp
// Good: ゼロ値で有効な状態
type Counter struct {
mu sync.Mutex
count int // ゼロ値は0で有効
}
func (c *Counter) Inc() {
c.mu.Lock()
c.count++
c.mu.Unlock()
}
// 初期化なしで使用可能
var c Counter
c.Inc()
// Good: 単一メソッドインターフェース
type Reader interface {
Read(p []byte) (n int, err error)
}
type Writer interface {
Write(p []byte) (n int, err error)
}
// 組み合わせで拡張
type ReadWriter interface {
Reader
Writer
}
// Good: ガード節で早期リターン
func process(item *Item) error {
if item == nil {
return errors.New("item is nil")
}
if item.ID == "" {
return errors.New("item ID is empty")
}
// メインロジック
return item.Save()
}