agentleFS
danmestasdanmestas/wardrobe/skills/golang-patterns/SKILL.md

golang-patterns

Skill4 starsChanged 7 months agoMITView on GitHub

Use when writing, reviewing, or refactoring Go code. Triggers on .go files, go.mod presence, or any task involving Go programming — concurrency (goroutines, channels, context), interfaces, generics, error handling, table-driven testing, or microservice/CLI architecture. Pairs with the `golang-pro` agent, which delegates pattern detail here.

26 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use kotlin-testing, ralphinho-rfc-pipeline and 10 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.
  • tpavanipradeepSkill

    kotlin-testing

    Kotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.

    Also in 5 projects that use this

  • InfopibeSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 8 projects that use this

  • saxon-ySkill

    configure-ecc

    Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.

    Also in 10 projects that use this

  • InfopibeSkill

    content-hash-cache-pattern

    Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

    Also in 9 projects that use this

  • mryeastcodeSkill

    santa-method

    Multi-agent adversarial verification with convergence loop. Two independent review agents must both pass before output ships.

    Also in 5 projects that use this

  • tpavanipradeepSkill

    bun-runtime

    Bun as runtime, package manager, bundler, and test runner. When to choose Bun vs Node, migration notes, and Vercel support.

    Also in 7 projects that use this

  • +4 more from Infopibe

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 5 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run gofmt and golangci-lint on all code

    line 107
  2. Very specific:

    Add context.Context as first param on all blocking operations

    line 108
  3. Distinctive:

    Write table-driven tests with subtests

    line 110
  4. Distinctive:

    Document all exported functions, types, and packages

    line 111
  5. Very specific:

    Use X | Y union constraints for generics (Go 1.18+)

    line 112
  6. Very specific:

    Run race detector on tests (-race flag)

    line 114
  7. Very specific:

    Use panic for normal error handling

    line 118
  8. Distinctive:

    When implementing Go features, provide:

    line 127
  9. Distinctive:

    Test file with table-driven tests

    line 130

“Common” is measured: kept by at least 6 in 10 of the 4 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

Golang Patterns

Idiomatic Go reference pack — concurrency, interfaces, generics, testing, project structure, plus the anti-patterns agents most commonly get wrong. Two-thesis stack:

  • Clear is better than clever. Boring, explicit, maintainable Go (Jon Bodner, Learning Go, 2nd ed.).
  • Production-grade by default. Bounded goroutine lifetimes, context threading, race-detector-clean tests, gofmt + golangci-lint on every change.

Reference Guide

Load detailed guidance based on context:

TopicReferenceLoad When
Concurrencyreferences/concurrency.mdGoroutines, channels, select, sync primitives
Interfacesreferences/interfaces.mdInterface design, io.Reader/Writer, composition
Genericsreferences/generics.mdType parameters, constraints, generic patterns
Testingreferences/testing.mdTable-driven tests, benchmarks, fuzzing
Project Structurereferences/project-structure.mdModule layout, internal packages, go.mod
Idiomatic Go (anti-patterns)references/idiomatic-go.mdQuick anti-pattern → idiomatic-fix tables, decision rules, agent-specific rationalization counters

Core Workflow

  1. Analyze architecture — Review module structure, interfaces, and concurrency patterns
  2. Design interfaces — Small, focused, defined at the consumer; composition over inheritance
  3. Implement — Idiomatic Go with proper error handling and context propagation; run go vet ./... before proceeding
  4. Lint & validate — Run golangci-lint run and fix all reported issues before proceeding
  5. Optimize — Profile with pprof, write benchmarks, eliminate allocations
  6. Test — Table-driven tests with -race, fuzzing, 80%+ coverage; race detector must pass before committing

Core Pattern Example

Goroutine with context cancellation and error propagation:

// worker runs until ctx is cancelled or an error occurs.
// Errors are returned via errCh; the caller must drain it.
func worker(ctx context.Context, jobs <-chan Job, errCh chan<- error) {
    for {
        select {
        case <-ctx.Done():
            errCh <- fmt.Errorf("worker cancelled: %w", ctx.Err())
            return
        case job, ok := <-jobs:
            if !ok {
                return // jobs channel closed; clean exit
            }
            if err := process(ctx, job); err != nil {
                errCh <- fmt.Errorf("process job %v: %w", job.ID, err)
                return
            }
        }
    }
}

func runPipeline(ctx context.Context, jobs []Job) error {
    ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
    defer cancel()

    jobCh := make(chan Job, len(jobs))
    errCh := make(chan error, 1)

    go worker(ctx, jobCh, errCh)

    for _, j := range jobs {
        jobCh <- j
    }
    close(jobCh)

    select {
    case err := <-errCh:
        return err
    case <-ctx.Done():
        return fmt.Errorf("pipeline timed out: %w", ctx.Err())
    }
}

Key properties: bounded goroutine lifetime via ctx, error propagation with %w, no goroutine leak on cancellation.

Constraints

MUST DO

  • Run gofmt and golangci-lint on all code
  • Add context.Context as first param on all blocking operations
  • Handle every error explicitly (no naked _ discards without justification)
  • Write table-driven tests with subtests
  • Document all exported functions, types, and packages
  • Use X | Y union constraints for generics (Go 1.18+)
  • Propagate errors with fmt.Errorf("...: %w", err)
  • Run race detector on tests (-race flag)

MUST NOT DO

  • Ignore errors (no _ = thatMightFail() without a comment)
  • Use panic for normal error handling
  • Spawn goroutines without a clear lifecycle
  • Skip context cancellation handling
  • Reach for reflection without a measured performance reason
  • Mix sync and async patterns carelessly
  • Hardcode configuration (functional options or env vars)

Output Templates

When implementing Go features, provide:

  1. Interface definitions (contracts first)
  2. Implementation files with proper package structure
  3. Test file with table-driven tests
  4. Brief explanation of any concurrency patterns used

Pairing

  • golang-pro agent — broader architectural / DevOps coverage; delegates pattern detail here. Load both when active Go development is in scope.

Provenance

Initial content adapted from jeffallan/claude-skills (MIT, skills/golang-pro) and the prior wardrobe idiomatic-go skill (Bodner-derived anti-pattern tables, now at references/idiomatic-go.md). See LICENSES.md.

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.