golang-design-patterns
Skill22 starsChanged 15 days agoMITView on GitHub
Design and review idiomatic Go construction, composition, options, state, retry, and lifecycle patterns against demonstrated invariants.
16 other projects use a version of this.
Adopted by
Most recently taken up by
- TeddyAlbina/skillstheir own version, first seen Nov 1, 2026
- samber/cc-skills-golangtheir own version, first seen Nov 1, 2026
- poizoncoded/skillstheir own version, first seen Nov 1, 2026
- damacus/agent-skillstheir own version, first seen Oct 29, 2026
- klawisha012/agentsynctheir own version, first seen Oct 25, 2026
- rockcookies/skillstheir own version, first seen Oct 13, 2026
Used with
Projects with it also use golang-samber-mo, golang-samber-ro and 4 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
guynhsichngeodiecSkillgolang-samber-mo
Monadic types for Golang using samber/mo — Option, Result, Either, Future, IO, Task, and State types for type-safe nullable values, error handling, and functional composition with pipeline sub-packages. Apply when using or adopting samber/mo, when the codebase imports `github.com/samber/mo`, or when considering functional programming patterns as a safety design for Golang.
Also in 7 projects that use this
guynhsichngeodiecSkillgolang-samber-ro
Reactive streams and event-driven programming in Golang using samber/ro — ReactiveX implementation with 150+ type-safe operators, cold/hot observables, 5 subject types (Publish, Behavior, Replay, Async, Unicast), declarative pipelines via Pipe, 40+ plugins (HTTP, cron, fsnotify, JSON, logging), automatic backpressure, error propagation, and Go context integration. Apply when using or adopting samber/ro, when the codebase imports github.com/samber/ro, or when building asynchronous event-driven pipelines, real-time data processing, streams, or reactive architectures in Go. Not for finite slice transforms (-> See golang-samber-lo skill).
Also in 7 projects that use this
alexastrumSkillgolang-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.
Also in 6 projects that use this
alexastrumSkillgolang-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`.
Also in 6 projects that use this
- +1 more from guynhsichngeodiec
- +1 more from alexastrum
Other versions16 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 16
- samber/cc-skills-golang★ 3.8ksame name
- unxed/f4★ 261same name
- klawisha012/agentsync★ 18same name
- saifoelloh/golang-best-practices-skill★ 15same name
- alexastrum/skl★ 11same name
- tstapler/dotfiles★ 8same name
- tquangkhai98/browser-profiles-manager★ 5same name
- damacus/agent-skills★ 2same name
- poizoncoded/skills★ 2same name
- TeddyAlbina/skills★ 2same name
6 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository56 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .kiro/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- aip-cordis-v4Skill
- aip-pr-deliverySkill
- codegraphSkill
- golang-benchmarkSkill
- golang-cliSkill
- golang-code-styleSkill
- golang-concurrencySkill
- golang-contextSkill
- golang-continuous-integrationSkill
- golang-databaseSkill
- golang-data-structuresSkill
- golang-dependency-injectionSkill
- golang-dependency-managementSkill
- golang-documentationSkill
- golang-error-handlingSkill
- golang-grpcSkill
- golang-hexagonal-architectureSkill
- golang-lintSkill
- golang-modernizeSkill
- golang-namingSkill
- golang-observabilitySkill
- golang-performanceSkill
- golang-popular-librariesSkill
- golang-project-layoutSkill
- golang-safetySkill
- golang-securitySkill
- golang-simplifySkill
- golang-solid-principle-reviewSkill
- golang-stretchr-testifySkill
- golang-structs-interfacesSkill
- golang-testingSkill
- golang-thermonuclear-code-reviewSkill
- golang-troubleshootingSkill
- kiro-debugSkill
- kiro-discoverySkill
- kiro-implSkill
- kiro-review-panelSkill
- kiro-reviewSkill
- kiro-spec-approveSkill
- kiro-spec-archiveSkill
- kiro-spec-batchSkill
- kiro-spec-designSkill
- kiro-spec-initSkill
- kiro-spec-quickSkill
- kiro-spec-requirementsSkill
- kiro-spec-statusSkill
- kiro-spec-tasksSkill
- kiro-steering-customSkill
- kiro-steeringSkill
- kiro-validate-designSkill
- kiro-validate-gapSkill
- kiro-validate-implSkill
- kiro-verify-completionSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 5 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 16 edited versions we read keep these.
5
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Check option validation/order, mutable captured configuration, constructors bypassed by zero values, and enum/state transitions at all …
- Distinctive: line 39
Use an options struct when fields are related and the configuration is naturally inspectable.
- Distinctive: line 45
Keep domain policy independent of transport, persistence, and vendor SDKs.
- Distinctive: line 47
Keep mutation at the owner boundary.
- Distinctive: line 63
Avoid init for business wiring.
“Common” is measured: kept by at least 6 in 10 of the 16 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go design patterns
Patterns are trade-offs, not mandatory shapes. Start from the invariant, ownership, and demonstrated variation in the codebase. Prefer direct composition and a small amount of duplication over a speculative framework.
Focused review
For a review, keep the work read-only unless fixes are requested. Establish the review base, supported versions, and relevant contract; inspect changed code plus the callers and tests needed to assess it. Stay within this skill’s lens.
- Name the invariant and demonstrated variation before recommending a pattern. Compare the proposed mechanism with direct code and count the states, branches, and ownership decisions it introduces.
- Check option validation/order, mutable captured configuration, constructors bypassed by zero values, and enum/state transitions at all public entrypoints.
- Trace retry eligibility, idempotency, partial downstream results, bounded delay, context cancellation, and side effects across attempts.
- Walk partial construction and explicit Close before runtime cleanup. Check wrappers/embedding preserve methods, errors, aliases, blocking, and serialization contracts.
Report each actionable finding with severity, confidence, file/symbol, trigger, consequence, and smallest remedy. Separate introduced/worsened defects from pre-existing debt, and state executed checks versus inference. If none survives validation, say so and identify coverage gaps.
Construction and composition
Use a constructor when a value needs validation, collaborators, or a non-obvious invariant. A zero value may be the best API when it is useful and safe. Return a concrete type by default; expose an interface only at a substitution boundary. Define interfaces near consumers and keep them small.
Functional options are useful when callers need a stable constructor with several optional, independent settings:
type Option func(*Client) error
func WithTimeout(d time.Duration) Option {
return func(c *Client) error {
if d < 0 { return errors.New("negative timeout") }
c.timeout = d
return nil
}
}Use an options struct when fields are related and the configuration is naturally inspectable. Ensure option application order is either irrelevant or documented.
Composition is Go's inheritance alternative. Embed only when promoted behavior and substitutability are intentional; otherwise use named fields. A type assertion should be rare and should handle failure.
Boundaries and data flow
Keep domain policy independent of transport, persistence, and vendor SDKs. Put adapters at package boundaries and translate wire types into canonical domain values. A closed enum or state machine may use a switch; do not invent a plugin registry for one fixed set.
Keep mutation at the owner boundary. Copy caller-owned maps/slices when retaining them, or document immutability. Use typed errors or wrapping for machine-readable classification:
if err != nil {
return fmt.Errorf("load profile: %w", err)
}A formatted string is not an API security boundary. Public handlers should map internal errors to a deliberately safe wire contract while preserving errors.Is/As internally.
Context, retry, and lifecycle
Pass context.Context through I/O and cancellation-aware operations. Do not store it. Retry only transient, idempotent operations; bound attempts and delay, use a timer/select on ctx.Done, and return the last error with context when canceled. Never retry after downstream content or a non-idempotent side effect without an explicit protocol.
A component that starts a goroutine, ticker, file watcher, server, or subscription owns its stop path. Prefer Close/Shutdown methods with idempotent behavior and a bounded context. A finalizer or runtime cleanup hook is not a deterministic replacement for Close. runtime.AddCleanup can handle unreachable objects in cycles, but provides neither prompt execution nor execution before process exit. The cleanup closure and argument must not retain the target. Keep explicit Close primary and coordinate fallback cleanup so it cannot double-release a resource.
Avoid init for business wiring. Package initialization follows dependency rules, but relying on source-file order or side effects across files is brittle. Construct dependencies in an explicit composition root.
Review checklist
For a pattern change, ask:
- What invariant does the pattern make easier to preserve?
- What variation is real today?
- Which package owns construction, state, cleanup, and error translation?
- Can a function value or concrete type replace an interface?
- Are aliases, retries, blocking, cancellation, and nil semantics documented?
- Is the change observable in focused tests?
Useful patterns include consumer-owned interfaces, functional options, adapter/port boundaries, explicit state machines, immutable value objects, and bounded worker ownership. Avoid singleton globals, service locators, hidden registries, generic “utils” packages, and patterns copied solely from another language.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

