Community程式設計與開發github.com

samber/golang-how-to

Golang 技能編排器 — 在任何 Go 編碼、審查、除錯或設置任務中保持活躍。它會讀取任務上下文,從 samber/cc-skills-golang 載入最相關的技能,經常一次載入多個技能。

golang-how-to 是什麼?

這是一個為 AI 代理設計的 Go 技能編排器,用於管理一組專門的 Go 開發技能(來自 samber/cc-skills-golang)。它的核心職責是根據當前任務上下文,智能選擇並同時載入多個相關技能。例如,撰寫 gRPC 服務時,它會載入 golang-grpc、golang-testing 和 golang-error-handling;除錯 panic 時,則載入 golang-troubleshooting、golang-safety 和 golang-benchmark。此外,它還能解決技能重疊的歧義(例如 performance 與 benchmark),並支援三種模式:Orchestrate(編排)、Disambiguate(歧義消除)和 Configure(配置)。Configure 模式會將強制載入指令寫入專案的代理配置檔(如 CLAUDE.md、AGENTS.md)。該技能依賴於 gopls 進行代碼導航,並明確區分了 godig、gopls、Context7 和 govulncheck 等工具在評估依賴項時的邊界。

相容平台✓Claude Code✓Codex CLI✓Cursor✓Gemini CLI
npx skills add https://github.com/samber/cc-skills-golang/tree/main/skills/golang-how-to

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

角色: 您是一名 Go 技能編排器。對於每個 Go 任務,請識別所有相關技能並同時載入它們——一個任務很少只屬於單一技能。

模式:

  • 編排 — 對於任何 Go 編碼、審查、除錯或設置任務,請同時載入主要技能以及所有適用的次要技能。
  • 消除歧義 — 當兩個技能似乎重疊時,顯示邊界表格。請參閱 disambiguation.md。
  • 配置 — 將 golang-how-to 本身的始終載入指令,以及可選的 ## Required Go skills 區塊,寫入專案的代理配置檔(CLAUDE.md、AGENTS.md 或同等文件)。請遵循 project-config.md。

提問: 在配置模式下,透過環境的提問工具向使用者提問——永遠不要使用純文字。一次只問一個問題,等待回答。如果環境沒有提問工具,則使用散文形式提問,並提供相同的選項。

依賴項: gopls — go install golang.org/x/tools/gopls@latest;Claude Code 內建的 LSP 工具也需要 ENABLE_LSP_TOOL=1 並連接 Go 語言伺服器(請參閱 使用 gopls 進行程式碼導覽)。

技能載入

對於每個任務,請同時載入主要技能和所有適用的次要技能。不要等待——在開始時一起載入它們。

意圖主要技能同時載入
設計 API,選擇模式golang-design-patternsgolang-structs-interfaces, golang-naming
命名類型、函式或套件golang-naminggolang-code-style
慣用方式處理錯誤golang-error-handlinggolang-safety (nil 密集型程式碼)
撰寫 goroutine、channel、syncgolang-concurrencygolang-context (如果需要取消)
傳遞截止時間 / 取消操作golang-contextgolang-concurrency (如果涉及 goroutine)
設計結構體、嵌入、使用介面golang-structs-interfacesgolang-design-patterns
資料庫查詢與交易golang-databasegolang-error-handling, golang-security
建立 gRPC 服務golang-grpcgolang-testing, golang-error-handling
建立 GraphQL APIgolang-graphqlgolang-testing, golang-error-handling
建立 CLI 命令樹golang-spf13-cobragolang-cli, golang-spf13-viper (如果有設定檔)
從環境變數/旗標/檔案分層設定golang-spf13-vipergolang-spf13-cobra
撰寫測試golang-testinggolang-stretchr-testify (如果使用 testify)
套用最佳化模式golang-performancegolang-benchmark (先測量)
使用 pprof / benchstat 測量golang-benchmarkgolang-performance (修正), golang-troubleshooting (根本原因)
除錯 panic 或異常行為golang-troubleshootinggolang-safety, golang-benchmark (如果與效能相關)
生產環境監控golang-observabilitygolang-performance (如果 SLO 違反)
審計安全漏洞golang-securitygolang-safety, golang-lint
審查格式與風格golang-code-stylegolang-naming, golang-lint
重構或重組現有程式碼golang-refactoringgolang-naming, golang-code-style, golang-project-layout
配置 golangci-lintgolang-lintgolang-code-style
撰寫 godoc / README / CHANGELOGgolang-documentationgolang-naming
設定新專案結構golang-project-layoutgolang-design-patterns, golang-dependency-injection, golang-lint
設定 CI/CD 管線golang-continuous-integrationgolang-lint, golang-security
選擇函式庫golang-popular-libraries相關函式庫特定技能
查詢套件的文件、版本、匯入者或 CVEgolang-pkg-go-devgolang-dependency-management
導覽、診斷或重構本地程式碼(定義、引用、重新命名)golang-gopls—
採用新的 Go 語言功能golang-modernizegolang-lint
使用 samber/lo(切片/映射輔助函式)golang-samber-logolang-data-structures, golang-performance
使用 samber/oops(結構化錯誤)golang-samber-oopsgolang-error-handling
使用 log/sloggolang-samber-sloggolang-observability, golang-error-handling
使用依賴注入golang-dependency-injectiongolang-google-wire 或 golang-uber-dig 或 golang-uber-fx 或 golang-samber-do

以上所有技能識別碼均為 samber/cc-skills-golang@<name> 的簡寫形式。

使用 gopls 進行程式碼導覽

gopls 為 Go 提供語義化程式碼智慧——前往定義、尋找引用、診斷、套件 API、符號搜尋、重構。→ 請參閱 samber/cc-skills-golang@golang-gopls 技能以了解三種存取方式(其自己的 MCP 伺服器、原生 LSP 工具及其 CLI)、完整功能矩陣以及高效的讀取/編輯工作流程。

gopls 僅能推理本地建置中存在且可解析的程式碼:您的工作區加上 go.sum 中精確鎖定的每個依賴項(包括 replace 指令)。對於與本地建置無關的任何事實(版本歷史、授權條款、生態系統範圍的匯入者、您尚未新增的套件),請使用 golang-pkg-go-dev (godig)。請參閱下方 godig vs gopls vs Context7 vs govulncheck 部分以了解完整的邊界。

godig vs gopls vs Context7 vs govulncheck

四個工具可以回答「這個依賴項是否可以安全使用」,而且它們的重疊程度並不像看起來那麼大:

  • Context7 是一個通用的、跨語言的文檔擷取工具——當沒有更具體的來源時很有用。對於一個 Go 套件或模組,godig 幾乎總是更好的選擇:它從 pkg.go.dev 拉取結構化的、Go 特定的資料——精確的版本、帶有簽名的匯出符號、可運行的範例、imported-by 以及已知的漏洞——而不是 Context7 通用抓取/策劃的文檔,後者不會暴露這種結構,並且可能延遲或遺漏較不知名的 Go 模組。僅在依賴項的文檔確實不存在或未在 pkg.go.dev 上索引時,才使用 Context7。
  • godig 回答關於已發布生態系統的問題:任何 Go 套件或模組,無論是否已在您的 go.mod 中——它呼叫遠端的 pkg.go.dev API,從不觸及您的本地檢出。其 vulns 命令會單獨報告某個套件/版本的已知 CVE,無論您的建置是否實際觸及該易受攻擊的程式碼路徑。
  • gopls (→ samber/cc-skills-golang@golang-gopls,透過其 MCP 伺服器、原生 LSP 工具或其 CLI) 回答關於您的特定建置的問題:您的程式碼加上每個依賴項

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

samber/golang-benchmark

Golang benchmarking, profiling, and performance measurement. Use when writing, running, or comparing Go benchmarks, profiling hot paths with pprof, interpreting CPU/memory/trace profiles, analyzing results with benchstat, setting up CI benchmark regression detection, or investigating production performance with Prometheus runtime metrics. Also use when the developer needs deep analysis on a specific performance indicator - this skill provides the measurement methodology, while `samber/cc-skills-golang@golang-performance` provides the optimization patterns.

samber/golang-cli

Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool — especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI unit testing. Also triggers when code uses cobra, viper, or urfave/cli. For cobra-specific APIs → See `samber/cc-skills-golang@golang-spf13-cobra` skill; for viper configuration layering → See `samber/cc-skills-golang@golang-spf13-viper` skill.

samber/golang-code-style

Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments help vs hurt. Use when writing or reviewing Go code, asking about style or clarity, or establishing project coding standards. Not for naming conventions (→ See `samber/cc-skills-golang@golang-naming` skill), linter configuration (→ See `samber/cc-skills-golang@golang-lint` skill), or doc comments (→ See `samber/cc-skills-golang@golang-documentation` skill).

samber/golang-concurrency

Golang concurrency patterns. Use when writing or reviewing concurrent Go code involving goroutines, channels, select, locks, sync primitives, errgroup, singleflight, worker pools, or fan-out/fan-in pipelines. Also triggers when you detect goroutine leaks, race conditions, channel ownership issues, or need to choose between channels and mutexes.

samber/golang-context

Idiomatic context.Context usage in Golang — propagation through API boundaries, cancellation, timeouts and deadlines, request-scoped values, context.WithoutCancel for background work outliving requests. Apply when designing context propagation across layers, debugging leaked or unexpired contexts, choosing between context.Background/TODO/WithoutCancel, or storing values in context. Not for code that merely accepts ctx as first parameter.

samber/golang-continuous-integration

CI/CD pipeline configuration using GitHub Actions for Golang projects — testing, linting, SAST, security scanning, code coverage, Dependabot, Renovate, GoReleaser, code review automation, and release pipelines. Use when setting up or improving Go project CI, configuring GitHub Actions workflows, adding linters or security scanners, automating dependency updates, or adding quality gates.

samber/golang-database

Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context propagation, and migration tooling. Use when writing, reviewing, or debugging Golang code that interacts with PostgreSQL, MariaDB, MySQL, or SQLite; for database testing; or for questions about database/sql, sqlx, or pgx. Does NOT generate database schemas or migration SQL.

samber/golang-data-structures

Golang data structures — slices (internals, capacity growth, preallocation, slices package), maps (internals, hash buckets, maps package), arrays, container/list/heap/ring, strings.Builder vs bytes.Buffer, generic collections, pointers (unsafe.Pointer, weak.Pointer), and copy semantics. Use when choosing or optimizing Go data structures, implementing generic containers, using container/ packages, unsafe or weak pointers, or questioning slice/map internals.

samber/golang-dependency-injection

Comprehensive guide for dependency injection (DI) in Golang. Covers why DI matters (testability, loose coupling, separation of concerns, lifecycle management), manual constructor injection, and DI library comparison (google/wire, uber-go/dig, uber-go/fx, samber/do). Use this skill when designing service architecture, setting up dependency injection, refactoring tightly coupled code, managing singletons or service factories, or when the user asks about inversion of control, service containers, or wiring dependencies in Go. For a specific DI library, → See `samber/cc-skills-golang@golang-google-wire`, `samber/cc-skills-golang@golang-uber-dig`, `samber/cc-skills-golang@golang-uber-fx`, or `samber/cc-skills-golang@golang-samber-do` skills.

samber/golang-dependency-management

Dependency management strategies for Golang projects — go.mod management, installing/upgrading packages, Minimal Version Selection, vulnerability scanning, outdated dependency tracking, binary size analysis, Dependabot/Renovate setup, conflict resolution, and go.work workspaces. Use when adding, removing, or upgrading Go dependencies, auditing vulnerabilities, resolving version conflicts, or setting up automated dependency updates.

samber/golang-design-patterns

Idiomatic Golang design patterns — functional options, constructors, error flow and cascading, resource management and lifecycle, graceful shutdown, resilience, architecture, dependency injection, data handling, streaming, and more. Apply when explicitly choosing between architectural patterns, implementing functional options, designing constructor APIs, setting up graceful shutdown, applying resilience patterns, or asking which idiomatic Go pattern fits a specific problem.

samber/golang-documentation

Comprehensive documentation guide for Golang projects, covering godoc comments, README, CONTRIBUTING, CHANGELOG, Go Playground, Example tests, API docs, and llms.txt. Use when writing or reviewing doc comments, documentation, adding code examples, setting up doc sites, or discussing documentation best practices. Triggers for both libraries and applications/CLIs.

samber/golang-error-handling

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handling rule, structured logging with slog, HTTP request logging middleware, and samber/oops for production errors. Built to make logs usable at scale with log aggregation 3rd-party tools. Apply when creating, wrapping, inspecting, or logging errors in Go code. For samber/oops specifics → See `samber/cc-skills-golang@golang-samber-oops` skill; for slog handler ecosystem → See `samber/cc-skills-golang@golang-samber-slog` skill.

samber/golang-google-wire

Compile-time dependency injection in Golang using google/wire — wire.NewSet, wire.Build, wire.Bind (interface→concrete), wire.Struct, wire.Value, wire.InterfaceValue, wire.FieldsOf, cleanup functions, //go:build wireinject injector files, and generated wire_gen.go. Apply when using or adopting google/wire, when the codebase imports `github.com/google/wire`, or when wiring an application graph at compile time via `wire.Build`. For runtime DI with reflection, see `samber/cc-skills-golang@golang-uber-dig` skill.

samber/golang-gopls

Golang semantic code intelligence via `gopls`, the official Go language server — go-to-definition, find references, call/implementation hierarchy, workspace symbol search, package API discovery, diagnostics, safe rename, refactors (extract/inline/fill/rewrite code actions), formatting, and generated tests. Reaches an agent via gopls's own MCP server (`go_*` tools), Claude Code's native `LSP` tool, or the `gopls` CLI. Use when navigating or refactoring Go code — jumping to a definition, finding call sites before a rename, understanding a file's or package's dependencies, running diagnostics after an edit, or extracting/inlining/renaming. Not for the published ecosystem — packages not in your `go.mod`, versions, licenses, importers — → See `samber/cc-skills-golang@golang-pkg-go-dev` skill (`godig`). Not for a whole-tree vulnerability audit → See `samber/cc-skills-golang@golang-security` skill (`govulncheck`).

samber/golang-graphql

Implements GraphQL APIs in Golang using gqlgen or graphql-go. Apply when building GraphQL servers, designing schemas, writing resolvers, handling subscriptions, or integrating GraphQL with existing Go HTTP services. Also apply when the codebase imports `github.com/99designs/gqlgen` or `github.com/graph-gophers/graphql-go`.

samber/golang-grpc

Provides gRPC usage guidelines, protobuf organization, and production-ready patterns for Golang microservices. Use when implementing, reviewing, or debugging gRPC servers/clients, writing proto files, setting up interceptors, handling gRPC errors with status codes, configuring TLS/mTLS, testing with bufconn, or working with streaming RPCs.

samber/golang-lint

Linting best practices and golangci-lint configuration for Golang projects — running linters, configuring .golangci.yml, suppressing warnings with nolint directives, interpreting lint output, and selecting linters. Use when configuring golangci-lint, asking about lint warnings or nolint suppressions, setting up code quality tooling, or choosing linters. Also use when the user mentions golangci-lint, go vet, staticcheck, or revive.

samber/golang-modernize

Modernize Golang code to use recent language features, standard library improvements, and idiomatic patterns. Trigger proactively when writing or reviewing Go code and old-style patterns are detected, or when encountering a deprecation warning. Also use when the user explicitly asks for modernization, a Go version upgrade, or a CI/tooling refresh.

samber/golang-naming

Go (Golang) naming conventions — covers packages, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, test functions, and subtest names. Use this skill when writing new Go code, reviewing or refactoring, choosing between naming alternatives (New vs NewTypeName, isConnected vs connected, ErrNotFound vs NotFoundError, StatusReady vs StatusUnknown at iota 0), debating Go package names (utils/helpers anti-patterns), or asking about Go naming best practices. Also trigger when the user mentions MixedCaps vs snake_case, ALL_CAPS constants, Get-prefix on getters, or error string casing. Do NOT use for general Go implementation questions that don't involve naming decisions.

相關技能