go-idiomatic-api-design
Design and review stable, idiomatic Go package APIs covering naming, exported declarations, embedding, receivers, typed-nil interfaces, generics, functional options, method sets, errors, wire contracts, compatibility, and examples. Use when creating a reusable Go package, reviewing its public surface, evolving an exported API, or choosing concrete types, functions, methods, fields, interfaces, or type parameters.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- go-idiomatic-api-design
- license
- MIT
- metadata
- { "tags": "go,golang,api-design,packages,interfaces,compatibility", "version": "0.2.0", "category": "Go", "displayName": "Go Idiomatic API Design" }
- description
- Design and review stable, idiomatic Go package APIs covering naming, exported declarations, embedding, receivers, typed-nil interfaces, generics, functional options, method sets, errors, wire contracts, compatibility, and examples. Use when creating a reusable Go package, reviewing its public surface, evolving an exported API, or choosing concrete types, functions, methods, fields, interfaces, or type parameters.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 6
- 参考文档agents/openai.yaml234 B
- 参考文档guidelines.md1.8 KB
- 参考文档references/api-design/examples.md1.5 KB
- 参考文档references/api-design/knowledge.md3.8 KB
- 参考文档references/api-design/rules.md2.6 KB
- 参考文档workflows/review-public-api.md1.6 KB
03 SKILL.md 正文
Go Idiomatic API Design
Design from the caller's code inward. Prefer the smallest coherent public surface that preserves invariants and can evolve without needless interfaces.
Core Workflow
- Identify callers, supported operations, and compatibility constraints.
- Sketch realistic call sites before choosing exported names or types.
- Keep packages cohesive and names clear without package-name stutter.
- Prefer concrete provider APIs; define narrow interfaces at consumers.
- Decide zero-value, mutation, copying, concurrency, and error contracts.
- Review embedding, receiver method sets, typed nils, generics, and option conflicts.
- Integrate standard interfaces only when their semantics truly match.
- Prove the public surface with external tests and executable examples.
- Review the change for accidental compatibility commitments.
Read Next
| Task | Load |
|---|---|
| Design or evolve an API | guidelines.md, workflows/review-public-api.md |
| Choose types, fields, methods, or interfaces | references/api-design/rules.md |
| Understand compatibility and method sets | references/api-design/knowledge.md |
| Review concrete patterns | references/api-design/examples.md |
Guardrails
- Do not export a field merely to avoid writing behavior.
- Do not define a provider-wide interface as a mirror of its methods.
- Do not accept an interface before a real consumer requires substitution.
- Do not use a standard interface when its conventional semantics are surprising.
- Do not claim conformance assertions prove behavior.
- Do not embed a public type unless every promoted behavior is intentional.
- Do not return a typed nil pointer through an interface success path.
- Check the module's Go language version before giving version-sensitive advice.
Source Notes
Guidance is transformed and paraphrased from Inanc Gumus, Go by Example: Programmer's Guide to Idiomatic and Testable Programs (Manning, 2025), especially Chapters 1, 2, 5, 9, and 10. Examples are original.
Embedding, receivers, generics, functional options, and typed-nil guidance also incorporates transformed material from Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022), Chapters 2 and 6.
Book: https://www.manning.com/books/go-by-example
Current language and documentation contracts should be verified against https://go.dev/ref/spec, https://go.dev/doc/comment, and the module's pinned Go version.
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.