agentleFS
aiproxeraiproxer/aiproxer/.agents/skills/golang-design-patterns/SKILL.md

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

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.
  • guynhsichngeodiecSkill

    golang-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

  • guynhsichngeodiecSkill

    golang-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

  • alexastrumSkill

    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.

    Also in 6 projects that use this

  • alexastrumSkill

    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`.

    Also in 6 projects that use this

  • +1 more from guynhsichngeodiec
  • +1 more from alexastrum

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
  1. Distinctive:

    Check option validation/order, mutable captured configuration, constructors bypassed by zero values, and enum/state transitions at all …

    line 15
  2. Distinctive:

    Use an options struct when fields are related and the configuration is naturally inspectable.

    line 39
  3. Distinctive:

    Keep domain policy independent of transport, persistence, and vendor SDKs.

    line 45
  4. Distinctive:

    Keep mutation at the owner boundary.

    line 47
  5. Distinctive:

    Avoid init for business wiring.

    line 63

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.