MCP HubMCP Hub
SKILL·FA2C61

go-coding-standards

eduardo-sl
更新日 27 days ago
5 閲覧
69
9
69
GitHubで表示
開発general

について

このスキルは、コードレビューや記述タスクにおいて、Effective GoとGo Code Review Commentsに基づいたGoスタイルのガイダンスを提供します。フォーマット規則、命名規則、インポート順序、その他の慣用的なパターンを適用します。アーキテクチャやパフォーマンスに関する懸念ではなく、スタイルとフォーマットのチェックに特化してご利用ください。

クイックインストール

Claude Code

推奨
メイン
npx skills add eduardo-sl/go-agent-skills -a claude-code
プラグインコマンド代替
/plugin add https://github.com/eduardo-sl/go-agent-skills
Git クローン代替
git clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-coding-standards

このコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします

ドキュメント

Go Coding Standards

Idiomatic Go conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms. All code MUST pass goimports, go vet, and staticcheck (or golangci-lint run) without errors.

1. Import Ordering

Group imports in this order, separated by blank lines:

import (
    // 1. Standard library
    "context"
    "fmt"
    "net/http"

    // 2. External packages
    "github.com/gorilla/mux"
    "log/slog"

    // 3. Internal/project packages
    "github.com/myorg/myproject/internal/service"
)

NEVER use dot imports. Use aliasing only to resolve conflicts.

2. Naming Conventions

Packages

  • Short, lowercase, single-word names. No underscores, no camelCase.
  • Name should describe what the package provides, not what it contains.
  • Avoid generic names: util, common, helpers, misc, base.

Functions & Methods

  • MixedCaps (exported) or mixedCaps (unexported). No underscores except in test files.
  • Getters: use Name(), NOT GetName(). Setters: use SetName().
  • Constructors: NewFoo() returns *Foo. If only one type in package: New().

Variables

  • Short names in tight scopes: i, n, err, ctx.
  • Descriptive names for wider scopes: userCount, retryTimeout.
  • Prefix unexported package-level globals with _: var _defaultTimeout = 5 * time.Second.
  • Do NOT shadow built-in identifiers (error, len, cap, new, make, close).

Interfaces

  • Single-method interfaces: method name + -er suffix (Reader, Writer, Closer).
  • Define interfaces where they are consumed, not where they are implemented.

3. Variable Declarations

Top-level

Use var for top-level declarations. Do NOT specify type when it matches the expression:

// ✅ Good
var _defaultPort = 8080
var _logger = slog.Default()

// ❌ Bad — redundant type
var _defaultPort int = 8080

Local

  • Prefer := for local variables.
  • Use var only when zero-value initialization is intentional and meaningful.
// ✅ Good — zero value is meaningful
var buf bytes.Buffer

// ✅ Good — short declaration
name := getUserName()

4. Struct Initialization

ALWAYS use field names. Never rely on positional initialization:

// ✅ Good
user := User{
    Name:  "Alice",
    Email: "[email protected]",
    Age:   30,
}

// ❌ Bad — positional, breaks on field reordering
user := User{"Alice", "[email protected]", 30}

Omit zero-value fields unless clarity requires them:

// ✅ Good — zero values omitted
user := User{
    Name: "Alice",
}

5. Reduce Nesting

Handle errors and special cases first with early returns. Reduce indentation levels:

// ✅ Good — early return
func process(data []Item) error {
    for _, v := range data {
        if !v.IsValid() {
            log.Printf("invalid item: %v", v)
            continue
        }

        if err := v.Process(); err != nil {
            return err
        }

        v.Send()
    }
    return nil
}

Eliminate unnecessary else blocks:

// ✅ Good
a := 10
if condition {
    a = 20
}

// ❌ Bad
var a int
if condition {
    a = 20
} else {
    a = 10
}

6. Grouping and Ordering

Group related declarations:

const (
    _defaultPort    = 8080
    _defaultTimeout = 30 * time.Second
)

var (
    _validTypes  = map[string]bool{"json": true, "xml": true}
    _defaultUser = User{Name: "guest"}
)

Function ordering within a file:

  1. Constants and variables
  2. New() / constructor functions
  3. Exported methods (sorted by importance, not alphabetically)
  4. Unexported methods
  5. Helper functions

Receiver methods should appear immediately after the type declaration.

7. Line Length

Soft limit of 99 characters. Break long function signatures:

func (s *Store) CreateUser(
    ctx context.Context,
    name string,
    email string,
    opts ...CreateOption,
) (*User, error) {

8. Defer Usage

Use defer for cleanup. It makes intent clear at the point of acquisition:

mu.Lock()
defer mu.Unlock()

f, err := os.Open(path)
if err != nil {
    return err
}
defer f.Close()

9. Enums

Start enums at 1 (or use explicit sentinel) so zero-value signals "unset":

type Status int

const (
    StatusUnknown Status = iota
    StatusActive
    StatusInactive
)

10. Use time Package Properly

  • Use time.Duration for durations, NOT raw integers.
  • Use time.Time for instants. Use time.Since(start) instead of time.Now().Sub(start).
  • External APIs: accept int or float64 and convert internally.
// ✅ Good
func poll(interval time.Duration) { ... }
poll(10 * time.Second)

// ❌ Bad
func poll(intervalSecs int) { ... }
poll(10)

Verification Checklist

Before considering code complete:

  1. goimports runs clean
  2. go vet ./... passes
  3. golangci-lint run passes (if configured)
  4. No shadowed built-in identifiers
  5. All imports properly grouped and ordered
  6. Struct initializations use field names
  7. No unnecessary nesting or else blocks

GitHub リポジトリ

eduardo-sl/go-agent-skills
パス: skills/(code-quality)/go-coding-standards
0
FAQ

よくある質問

go-coding-standards Skillとは何ですか?

go-coding-standards はeduardo-sl が作成した Claude Skillです。Skillは、Claudeが必要に応じて読み込む指示とリソースをまとめ、追加の指示なしで go-coding-standards に関連するタスクを実行できるようにします。

go-coding-standards をインストールするには?

このページのインストールコマンドを使用してください。go-coding-standards をプラグインとして Claude Code に追加するか、リポジトリを skills ディレクトリにクローンし、Claudeを再起動してSkillを読み込みます。

go-coding-standards はどのカテゴリに属しますか?

go-coding-standards は 開発 カテゴリに属します。

go-coding-standards は無料で利用できますか?

はい。go-coding-standards は AIMCP に掲載されており、無料でインストールできます。

関連スキル

qmd
開発

qmdは、BM25、ベクトル埋め込み、およびリランキングを組み合わせたハイブリッド検索を用いて、ローカルファイルのインデックス作成と検索を可能にするローカル検索・インデックス作成CLIツールです。コマンドラインでの使用と、Claudeとの統合のためのMCP(Model Context Protocol)モードの両方をサポートしています。このツールは埋め込みにOllamaを使用し、インデックスをローカルに保存するため、ターミナルから直接ドキュメントやコードベースを検索するのに最適です。

スキルを見る
subagent-driven-development
開発

このスキルは、各独立したタスクに対して新規のサブエージェントを起動し、タスク間でコードレビューを実施しながら実装計画を実行します。レビュープロセスを通じて品質基準を維持しつつ、迅速な反復を可能にします。同一セッション内で主に独立したタスクに取り組む際に本スキルをご利用いただくことで、組み込まれた品質チェックを伴う継続的な進捗を確保できます。

スキルを見る
mcporter
開発

mcporterスキルは、開発者がClaudeから直接Model Context Protocol(MCP)サーバーを管理および呼び出せるようにします。このスキルは、利用可能なサーバーの一覧表示、引数を指定したツールの呼び出し、認証およびデーモンのライフサイクル管理を行うコマンドを提供します。開発ワークフローにおいてMCPサーバーの機能を統合およびテストする際に、このスキルをご利用ください。

スキルを見る
adk-deployment-specialist
開発

このスキルは、A2Aプロトコルを使用してVertex AI ADKエージェントをデプロイおよびオーケストレーションし、AgentCardの発見、タスク送信、およびコード実行サンドボックスやメモリバンクなどのサポートツールを管理します。Python、Java、またはGoで、順次、並列、またはループのオーケストレーションパターンを用いたマルチエージェントシステムの構築を可能にします。Google Cloud上でADKエージェントのデプロイやエージェントワークフローのオーケストレーションを求められた際にご利用ください。

スキルを見る