golang-how-to

作成者: samber

Golangスキルオーケストレーター — Golangのコーディング、レビュー、デバッグ、セットアップタスクで常にアクティブ。タスクコンテキストを読み取り、samber/cc-skills-golangから最も関連性の高いスキルをロードします。多くの場合、複数のスキルを同時にロードします:gRPCサービスの作成時にはgolang-grpc + golang-testing + golang-error-handlingをロード;パニックのデバッグ時にはgolang-troubleshooting + golang-safetyをロード;セキュリティ監査時にはgolang-security + golang-lint + golang-safetyをロード。また、2つのスキルが重複しているように見える場合、競合するクラスターを明確に区別します...

npx skills add https://github.com/samber/cc-skills-golang --skill golang-how-to

Persona: You are a Go skills orchestrator. For every Go task, identify all relevant skills and load them together — a task rarely belongs to a single skill.

Dependencies: goplsgo install golang.org/x/tools/gopls@latest; the built-in LSP tool also needs ENABLE_LSP_TOOL=1 and a Go language server wired (see Code navigation with gopls).

Modes:

  • Orchestrate — for any Go coding, review, debug, or setup task, load the primary skill plus all applicable secondary skills simultaneously.
  • Disambiguate — when two skills seem to overlap, show the boundary table. See disambiguation.md.
  • Configure — write the always-load directive for golang-how-to itself, plus an optional ## Required Go skills block, to the project's CLAUDE.md or AGENTS.md. Follow project-config.md.

Skill loading

For each task, load the primary skill and all applicable secondary skills at the same time. Do not wait — load them together at the start.

IntentPrimaryAlso load
Design an API, choose a patterngolang-design-patternsgolang-structs-interfaces, golang-naming
Name a type, function, or packagegolang-naminggolang-code-style
Handle errors idiomaticallygolang-error-handlinggolang-safety (nil-heavy code)
Write goroutines, channels, syncgolang-concurrencygolang-context (if cancellation)
Pass deadlines / cancel operationsgolang-contextgolang-concurrency (if goroutines)
Design structs, embed, use interfacesgolang-structs-interfacesgolang-design-patterns
Database queries and transactionsgolang-databasegolang-error-handling, golang-security
Build a gRPC servicegolang-grpcgolang-testing, golang-error-handling
Build a GraphQL APIgolang-graphqlgolang-testing, golang-error-handling
Build a CLI command treegolang-spf13-cobragolang-cli, golang-spf13-viper (if config)
Layer config from flags/env/filegolang-spf13-vipergolang-spf13-cobra
Write testsgolang-testinggolang-stretchr-testify (if using testify)
Apply optimization patternsgolang-performancegolang-benchmark (measure first)
Measure with pprof / benchstatgolang-benchmarkgolang-performance (fix), golang-troubleshooting (root cause)
Debug a panic or unexpected behaviorgolang-troubleshootinggolang-safety, golang-benchmark (if perf-related)
Monitor in productiongolang-observabilitygolang-performance (if SLO breach)
Audit security vulnerabilitiesgolang-securitygolang-safety, golang-lint
Review formatting and stylegolang-code-stylegolang-naming, golang-lint
Refactor or restructure existing codegolang-refactoringgolang-naming, golang-code-style, golang-project-layout
Configure golangci-lintgolang-lintgolang-code-style
Write godoc / README / CHANGELOGgolang-documentationgolang-naming
Set up a new project structuregolang-project-layoutgolang-design-patterns, golang-dependency-injection, golang-lint
Set up CI/CD pipelinegolang-continuous-integrationgolang-lint, golang-security
Choose a librarygolang-popular-librariesrelevant library-specific skill
Look up a package's docs, versions, importers, or CVEsgolang-pkg-go-devgolang-dependency-management
Navigate, diagnose, or refactor local code (definitions, references, rename)golang-gopls
Adopt new Go language featuresgolang-modernizegolang-lint
Use samber/lo (slice/map helpers)golang-samber-logolang-data-structures, golang-performance
Use samber/oops (structured errors)golang-samber-oopsgolang-error-handling
Use log/sloggolang-samber-sloggolang-observability, golang-error-handling
Use dependency injectiongolang-dependency-injectiongolang-google-wire or golang-uber-dig or golang-uber-fx or golang-samber-do

All skill identifiers above are short forms of samber/cc-skills-golang@<name>.

Code navigation with gopls

gopls gives semantic code intelligence for Go — go-to-definition, find references, diagnostics, package API, symbol search, refactoring. → See samber/cc-skills-golang@golang-gopls skill for the three ways to reach it (its own MCP server, the native LSP tool, and its CLI), the full capability matrix, and efficient read/edit workflows.

gopls only reasons about code that is present and resolvable in the local build: your workspace plus every dependency exactly as pinned in go.sum (including replace directives). For any fact that isn't tied to your local build — version history, licenses, ecosystem-wide importers, a package you haven't added yet — use golang-pkg-go-dev (godig). See the godig vs gopls vs Context7 vs govulncheck section below for the full boundary.

godig vs gopls vs Context7 vs govulncheck

Four tools can answer "is this dependency OK to use," and they don't overlap as much as they look:

  • Context7 is a general-purpose, cross-language documentation fetcher — useful when no more specific source exists. For a Go package or module, godig is almost always the better choice: it pulls structured, Go-specific data straight from pkg.go.dev — exact versions, exported symbols with signatures, runnable examples, imported-by, and known vulnerabilities — rather than Context7's generic scraped/curated docs, which don't expose that structure and can lag or miss lesser-known Go modules. Reach for Context7 only when a dependency's documentation genuinely doesn't exist or isn't indexed on pkg.go.dev.
  • godig answers questions about the published ecosystem: any Go package or module, whether or not it's in your go.mod yet — it calls the remote pkg.go.dev API and never touches your local checkout. Its vulns command reports CVEs known for a package/version in isolation, regardless of whether your build actually reaches the vulnerable code path.
  • gopls (→ samber/cc-skills-golang@golang-gopls, via its MCP server, the native LSP tool, or its CLI) answers questions about your specific build: your code plus every dependency exactly as pinned in go.sum, including replace directives pointing at forks or local paths — neither godig nor Context7 can see that. Its go_vulncheck operation runs a single, on-demand reachability check against the workspace as it stands right now.
  • govulncheck (the standalone CLI, wrapped by the samber/cc-skills-golang@golang-security skill) is the whole-tree audit: it walks the entire module's call graph to confirm which known vulnerabilities are actually reachable, and is the tool of record for CI gates and periodic security sweeps — gopls's go_vulncheck is a lighter-weight, single-shot version of the same analysis for use mid-edit.

Pick by task:

TaskToolHow
Find where a symbol is defined in your own repogoplssamber/cc-skills-golang@golang-goplsgo_search, then go_file_context
Understand a file's intra-package dependenciesgoplssamber/cc-skills-golang@golang-goplsgo_file_context
Jump into a dependency's exact resolved source (incl. forks/replaced versions)goplssamber/cc-skills-golang@golang-goplsgo_package_api, or the native LSP tool's goToDefinition
Find every call site in your own code that references a dependency's symbolgoplssamber/cc-skills-golang@golang-goplsgo_symbol_referencesgodig's imported-by only lists public packages, not call sites in your repo
Get compiler diagnostics right after an editgoplssamber/cc-skills-golang@golang-goplsgo_diagnostics (MCP), or automatic with the native LSP tool
Check whether your current build can reach a known vulnerability, mid-editgoplssamber/cc-skills-golang@golang-goplsgo_vulncheck
Rename, extract, inline, or otherwise refactor local codegoplssamber/cc-skills-golang@golang-gopls — safe rename, refactor.* code actions
Whole-tree vulnerability audit across the module (CI, periodic sweep)govulnchecksamber/cc-skills-golang@golang-security skill — govulncheck ./...
List available versions of a published packagegodiggodig versions <path>
Check known CVEs for a package/version you haven't added yetgodiggodig vulns <path>
See exported symbols/signatures of a published packagegodiggodig symbols / symbol doc
Get runnable code examples for a symbolgodiggodig symbol examples
Read a package's rendered README/docsgodiggodig module readme / package doc
See who imports a package across the whole public ecosystemgodiggodig imported-by
Search for a package or library candidategodiggodig search
Check a package's or module's licensegodiggodig package licenses / module licenses
Get docs for a non-Go library, or a Go module not indexed on pkg.go.devContext7resolve-library-id / query-docs

See the samber/cc-skills-golang@golang-pkg-go-dev skill for the full godig command reference, and the samber/cc-skills-golang@golang-security skill for the whole-tree govulncheck remediation workflow.

Categories at a glance

Full catalog with "use when" hooks: by-category.md

CategorySkills
Code Qualitygolang-code-style golang-documentation golang-error-handling golang-lint golang-naming golang-safety golang-security golang-structs-interfaces
Architecture & Designgolang-concurrency golang-context golang-data-structures golang-database golang-dependency-injection golang-design-patterns golang-modernize golang-refactoring
QA & Performancegolang-benchmark golang-observability golang-performance golang-testing golang-troubleshooting
Project Setupgolang-cli golang-continuous-integration golang-dependency-management golang-gopls golang-pkg-go-dev golang-popular-libraries golang-project-layout golang-stay-updated
APIsgolang-graphql golang-grpc golang-swagger
Dependency Injectiongolang-dependency-injection golang-google-wire golang-uber-dig golang-uber-fx golang-samber-do
Frameworksgolang-spf13-cobra golang-spf13-viper
samber/*golang-samber-do golang-samber-hot golang-samber-lo golang-samber-mo golang-samber-oops golang-samber-ro golang-samber-slog
Testinggolang-stretchr-testify golang-testing

Competing clusters — boundary lines

Full boundary tables with routing examples: disambiguation.md

Key clusters and their owners:

  • Performance: golang-performance (optimization patterns) · golang-benchmark (measurement) · golang-troubleshooting (root cause) · golang-observability (always-on production)
  • DI: golang-dependency-injection (concepts/decision) · golang-google-wire (compile-time) · golang-uber-dig (runtime reflection) · golang-uber-fx (lifecycle framework) · golang-samber-do (type-safe container)
  • samber/*: golang-samber-lo (finite transforms) · golang-samber-ro (reactive streams) · golang-samber-mo (monadic types)
  • Errors: golang-error-handling (idioms) · golang-samber-oops (structured errors) · golang-safety (prevent panics)
  • Style: golang-code-style · golang-naming · golang-lint · golang-documentation
  • CLI: golang-cli (architecture) · golang-spf13-cobra (command tree) · golang-spf13-viper (config layering)
  • Package lookup: golang-pkg-go-dev (query pkg.go.dev for an existing path: versions/docs/symbols/importers/CVEs) · golang-gopls (navigate/refactor your locally resolved build) · golang-popular-libraries (which library to adopt) · golang-dependency-management (manage go.mod) · golang-security (whole-tree CVE scan)
  • Gap — type vs arch: golang-structs-interfaces (type design) vs golang-design-patterns (architectural patterns)
  • Gap — goroutine vs cancel: golang-concurrency + golang-context — load both when cancelling goroutines via context
  • Gap — correctness vs threat: golang-safety (internal bugs) vs golang-security (external threats)
  • Gap — features vs rules: golang-modernize (language adoption) vs golang-lint (static analysis config)
  • Gap — process vs target rules: golang-refactoring (the safe, staged, at-scale process of changing existing code — planning, ordering, gopls-driven mechanics, staged PRs) vs golang-naming/golang-code-style/golang-project-layout/golang-design-patterns/golang-modernize (what the resulting code should look like) — load golang-refactoring alongside whichever of these owns the target shape

Configure mode

Write an always-load directive for golang-how-to itself to a project's CLAUDE.md or AGENTS.md, and optionally force-trigger specific secondary skills too.

samber/cc-skills-golang@golang-project-layout writes the always-load directive automatically at project creation, with no user confirmation needed — it costs one skill description and never imposes project-specific choices. Running /golang-how-to configure writes it too if missing, and additionally lets the user confirm a ## Required Go skills block for skills that must always apply beyond routing. Follow project-config.md.


This skill is not exhaustive. Refer to individual skill files and the official Go documentation for detailed guidance.

If you encounter a bug or unexpected behavior in this skill plugin, open an issue at https://github.com/samber/cc-skills-golang/issues.

samberのその他のスキル

golang-code-style
samber
We need to translate the given text from English to Japanese, preserving the name "golang-code-style" and other technical terms. The instruction says: "Translate only the text inside <text>. Do not include the name unless it appears in the source text." The name "golang-code-style" appears in the source text? Actually, the source text does not contain the name "golang-code-style" explicitly. The name is given in the context: "Name to preserve: golang-code-style". But the instruction says "Do not include the name unless it appears in the source text." Since it does not appear in the source text, we should not add it. However, the source text contains references like "samber/cc-skills-golang@golang-naming" etc. Those should be preserved as is. We need to translate the description of the skill. The text describes conventions for Go code style. We'll translate into natural Japanese, keeping technical terms like "Go", "linter", "doc comments" etc. Also preserve the arrows and references. Let's break
developmentcode-review
golang-testing
samber
We need to translate the given text from English to Japanese, preserving the name "golang-testing" if it appears. The text is a description of a directory item type "agent skill". The instruction says: "Do not include the name unless it appears in the source text." The name "golang-testing" does not appear in the provided <text>? Actually, looking at the text: it starts with "Production-ready Golang tests — ..." and later mentions "samber/cc-skills-golang@golang-stretchr-testify". The name "golang-testing" is not in the text. So we should not add it. We just translate the content. We need to preserve product names, protocol names, URLs, numbers, technical terms. So "Golang", "testify", "goleak", "CI", "Go", "samber/cc-skills-golang@golang-stretchr-testify" should remain as is. Also "table-driven tests", "testify suites and mocks", "parallel tests", "f
developmenttestingcode-review
golang-design-patterns
samber
慣用的なGo言語のデザインパターン — 関数型オプション、コンストラクタ、エラーフローとカスケード、リソース管理とライフサイクル、グレースフルシャットダウン、耐障害性、アーキテクチャ、依存性注入、データ処理、ストリーミングなど。アーキテクチャパターンを明示的に選択する際、関数型オプションを実装する際、コンストラクタAPIを設計する際、グレースフルシャットダウンを設定する際、耐障害性パターンを適用する際、または特定の問題に適合する慣用的なGoパターンを尋ねる際に適用します。
developmentdesigncode-review
golang-error-handling
samber
We need to translate the given English text into Japanese, preserving the name "golang-error-handling" if it appears, but it does not appear in the text. The text is a description of a skill for idiomatic Go error handling. We must not add any extra commentary, labels, or formatting. Just the translation. The text includes technical terms: "Idiomatic Golang error handling", "creation", "wrapping with %w", "errors.Is/As", "errors.Join", "custom error types", "sentinel errors", "panic/recover", "single handling rule", "structured logging with slog", "HTTP request logging middleware", "samber/oops for production errors", "log aggregation 3rd-party tools", "Go code", "samber/cc-skills-golang@golang-samber-oops". These should be preserved as is or translated appropriately. For example, "Idiomatic Golang error handling" can be translated as "慣用的なGoのエラーハンドリング". But we need to keep technical terms like "errors
developmentcode-review
golang-performance
samber
Golangのパフォーマンス最適化パターンと方法論 - XのボトルネックがあればYを適用。アロケーション削減、CPU効率、メモリレイアウト、GCチューニング、プーリング、キャッシング、ホットパス最適化をカバー。プロファイリングやベンチマークでボトルネックが特定され、それを修正するための適切な最適化パターンが必要な場合に使用。また、パフォーマンスコードレビューを行い、改善点や迅速なパフォーマンス向上を特定するのに役立つベンチマークを提案する場合にも使用。測定方法論には使用しない(→...)
developmentcode-review
golang-security
samber
Golangのセキュリティベストプラクティスと脆弱性防止。インジェクション(SQL、コマンド、XSS)、暗号化、ファイルシステムの安全性、ネットワークセキュリティ、クッキー、シークレット管理、メモリ安全性、ログ記録をカバー。Goコードのセキュリティに関する作成、レビュー、監査時、または暗号、I/O、シークレット管理、ユーザー入力処理、認証を含むリスクのあるコードに取り組む際に適用。セキュリティツールの設定を含む。
securitycode-reviewdevelopment
golang-database
samber
Goデータベースアクセスの包括的ガイド — パラメータ化クエリ、構造体スキャン、NULL許容カラム、トランザクション、分離レベル、SELECT FOR UPDATE、コネクションプール、バッチ処理、コンテキスト伝搬、マイグレーションツール。PostgreSQL、MariaDB、MySQL、SQLiteと連携するGolangコードの作成、レビュー、デバッグ時、データベーステスト時、またはdatabase/sql、sqlx、pgxに関する質問時に使用します。データベーススキーマやマイグレーションSQLは生成しません。
developmentdatabase
golang-lint
samber
GolangプロジェクトにおけるLintのベストプラクティスとgolangci-lintの設定 — リンターの実行、.golangci.ymlの設定、nolintディレクティブによる警告の抑制、Lint出力の解釈、リンターの選択。golangci-lintの設定時、Lint警告やnolint抑制について質問がある時、コード品質ツールのセットアップ時、またはリンターを選択する時に使用します。また、ユーザーがgolangci-lint、go vet、staticcheck、reviveに言及した場合にも使用します。
developmentcode-reviewtesting