Community编程与开发github.com

Go 包与模块查询(godig)

通过 godig(pkg.go.dev API 客户端)查询 Go 包和模块的信息:文档、API 签名、符号、使用示例、版本、许可证、漏洞及导入者。只读操作,无需认证。

Go 包与模块查询(godig) 是什么?

本技能基于 `godig` 工具,封装了 pkg.go.dev 官方 API 的所有只读查询功能,帮助你在 Go 开发生态中快速检索任意已发布包或模块的信息。它支持 CLI 和 MCP Server 两种运行方式,所有操作均无需认证。使用 godig,你可以查询包的文档、符号、版本列表、许可证、漏洞、导入者以及模块的依赖关系。对于 Go 相关的查询,应优先于 Context7 使用。注意:此技能不用于本地已解析的构建(由 gopls 负责)、漏洞全量审计(由 govulncheck 处理)、库选择建议或依赖升级。典型应用场景包括:“有哪些版本可用?”、“这个包有已知漏洞吗?”、“显示包 X 的文档”或“哪些包导入了这个包?”。MCP 服务器支持 stdio 和 streamable HTTP 传输,并可通过命令行全局标志或 `GODIG_*` 环境变量定制输出格式、超时、日志级别等。建议首先使用 `overview` 命令获取紧凑摘要,仅在需要全文时才使用 `doc`、`examples` 等大型命令,并推荐使用 `-o md` 输出以便在聊天中呈现良好的 Markdown 结果。

兼容平台✓Claude Code✓Codex CLI✓Cursor✓Windsurf
npx skills add https://github.com/samber/cc-skills-golang/tree/main/skills/golang-pkg-go-dev

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

golang-pkg-go-dev

依赖: godig — go install github.com/samber/godig/cmd/godig@latest(或使用已注册的 godig MCP 服务器 / 托管实例)。

godig 查询 pkg.go.dev API。用于回答关于 Go 包和模块的问题:文档、符号、版本、导入者和漏洞。它可以作为 CLI 和 MCP 服务器运行,所有操作均为只读且无需认证。

何时使用此技能

在遇到如下问题时触发:

  • "github.com/samber/lo 有哪些可用版本?"
  • "golang.org/x/text 是否有已知漏洞?"
  • "显示包 X 的文档 / 符号。"
  • "哪些包导入了 X?"
  • "搜索 Go 包 Y。"

在 godig、gopls、Context7 和 govulncheck 之间选择

简言之:godig 回答关于已发布生态系统的问题(即使包不在你的 go.mod 中也能工作);gopls 推理你本地解析后的构建(go.sum,包括 replace 的 fork);Context7 是针对非 Go 或未索引文档的备选方案;govulncheck 是全树漏洞审计(→ samber/cc-skills-golang@golang-security)。有关将 gopls(MCP 服务器、原生 LSP 工具和 CLI)与 Claude Code 集成的信息,请参见 samber/cc-skills-golang@golang-gopls 技能,有关任务到工具的完整矩阵,请参见 samber/cc-skills-golang@golang-how-to 技能中的 "godig vs gopls vs Context7 vs govulncheck" 部分。

设置

安装

go install github.com/samber/godig/cmd/godig@latest

注册 MCP 服务器(可选)

godig mcp 默认运行在 stdio 上,或使用 --transport http 运行在 streamable HTTP 上。该命令与 harness 无关——任何支持 MCP 的主机都可以指向它。Claude Code 通过其自己的 CLI 注册它:

stdio(客户端按需启动 godig):

claude mcp add pkg-go-dev -- godig mcp

streamable HTTP(共享服务器在 /mcp 上,默认端口 :8080):

godig mcp --transport http --addr :8080
claude mcp add --transport http pkg-go-dev http://localhost:8080/mcp

托管实例(无需安装)——公共服务器运行在 https://godig.samber.dev/mcp:

claude mcp add --transport http pkg-go-dev https://godig.samber.dev/mcp

其他支持 MCP 的 harness(Cursor、Windsurf 等)各有自己的 MCP 服务器注册方式——在其各自的设置文件中指向相同的 godig mcp 命令或托管 URL,而不是共享的配置格式。

CLI 和 MCP 服务器暴露相同的操作,且名称匹配。当安装了 godig 时,优先使用 CLI;托管实例是未安装时的备选。

命令

全局标志(所有命令): -o/--output table|json|raw|md(默认 table——在聊天中传 -o md),--base-url(pkg.go.dev API),--vuln-base-url(Go 漏洞数据库,由 vulns 和 overview 使用),--timeout,--log-level debug|info|warn|error|off。所有标志也可通过 GODIG_* 环境变量设置。

命令参数特有标志用途
overview<path>--version紧凑摘要(元数据、版本、许可证、漏洞)——从此开始
search<query>--symbol --limit --filter搜索包(可选导出符号)
package info<path>--module --version包元数据
package imports<path>--module --version此包导入的包(纯列表)
package doc<path>--module --version --goos --goarch --format md|text|html|markdown完整包文档(大)
package examples<path>--module --version --goos --goarch --symbol可运行示例(大;用 --symbol 限定范围)
package licenses<path>--module --version许可证文件,完整文本(大)
symbol doc<path> <symbol>--module --version --goos --goarch单个符号的签名 + 文档(高令牌效率)
symbol examples<path> <symbol>--module --version --goos --goarch单个符号的可运行示例
symbols<path>--module --version --goos --goarch --limit --filter列出导出的符号
module info<path>--version模块元数据
module licenses<path>--version模块许可证文件(大)
module readme<path>--version模块 README,完整 Markdown(大)
dependencies<path>--versiongo.mod 依赖:requires / replaces / excludes / go 指令
packages<path>--version --limit --filter模块中包含的包
versions<path>--limit --filter所有版本,最新优先
major-versions<path>--limit --filter --exclude-pseudo主要版本(v1, v2 …)作为独立模块存在
imported-by<path>--module --version --limit --filter导入此包的包
vulns<path>--version --limit已知漏洞(来自 Go 漏洞数据库)
mcp—--transport stdio|http --addr --cache-ttl --cache-size作为 MCP 服务器运行
version——打印 godig 版本 / 提交 / 构建日期

当 godig 作为 MCP 服务器运行时,上述每个数据命令都会暴露为同名的操作。

退出码: 0 成功,1 运行时错误(网络、包未找到),2 使用错误——参数或标志缺失/无效(例如非正数的 --limit),或命令组调用时没有子命令(godig package)。检查是否为 2 以区分格式错误的调用和失败的查找。

每个命令的完整 -o md 输出: sample-output.md

提示

  • 从 overview 开始——一次调用返回紧凑摘要(元数据、最新 + 近期版本、许可证类型、漏洞)。仅在需要完整文本时才使用 doc/examples/module readme/licenses(大)。
  • 始终传递 -o md 以便结果在聊天中呈现为 Markdown(表格或原始文档/README)。其他格式存在(table 默认、json、raw),但在此处优先使用 md。
  • <path> 是完整导入路径,例如 github.com/samber/lo——将其作为位置参数传递。
  • --version 固定到特定模块版本(v1.5.0、latest、master、main);--module 用于消除包所属模块的歧义。
  • --filter 使用 Go 布尔表达式在服务端缩小列表结果——参见过滤器语法。
  • --goos/--goarch 设置文档/符号的构建上下文(例如 linux/amd64)。
  • 当你只需要单个符号的信息时,优先使用 symbol doc/symbol examples,而不是包级别的 package doc/package examples。

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-how-to

Golang skills orchestrator — always active on any Golang coding, review, debug, or setup task. Reads the task context and loads the most relevant skills from samber/cc-skills-golang, often multiple at once: writing a gRPC service loads golang-grpc + golang-testing + golang-error-handling; debugging a panic loads golang-troubleshooting + golang-safety; auditing security loads golang-security + golang-lint + golang-safety. Also: disambiguates competing clusters when two skills seem to overlap (performance vs benchmark vs troubleshooting, samber/lo vs mo vs ro, DI cluster, safety vs security), and configures the project's agent-config file (CLAUDE.md, AGENTS.md, GEMINI.md, Cursor rules, or Copilot instructions) to force-trigger skills in a project (/golang-how-to configure).

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.

相关技能