Skip to content
Development
Skill

/go

Use when writing Go services, CLIs, or libraries. Covers idiomatic error wrapping, goroutine and context discipline, interface design, table-driven tests, and the race detector. Trigger on "goroutine leak", "how should i wrap this error in go", "race detector is flagging this",

From plugin
claude-skills-collection
34137 skills

Claude Code

$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill go --agent claude-code

SKILL.md

go.SKILL.md
name: go
description: Use when writing Go services, CLIs, or libraries. Covers idiomatic error wrapping, goroutine and context discipline, interface design, table-driven tests, and the race detector. Trigger on "goroutine leak", "how should i wrap this error in go", "race detector is flagging this", "write table-driven tests for this". Do not use for designing a CLI's flags and exit codes — see the cli-development skill.
metadata:
  category: languages
  version: 1.0.0
  tags: [go, golang, concurrency, context, testing]

Go

Purpose

Write Go that is boring in the best sense: explicit errors, bounded concurrency, small interfaces, and tests that read like a specification.

When to Use

  • Building HTTP services, gRPC servers, or CLI tools in Go.
  • Reviewing Go code for concurrency correctness or leaked goroutines.
  • Designing package boundaries and interfaces.
  • Diagnosing performance with pprof or the race detector.

Capabilities

  • Idiomatic error handling: wrapping, `errors.Is`, `errors.As`, sentinel errors.
  • Concurrency: contexts, worker pools, `errgroup`, channel patterns, graceful shutdown.
  • Interface design at the point of consumption.
  • Table-driven tests, golden files, fuzzing, benchmarks.
  • Profiling with pprof; escape analysis and allocation reduction.

Inputs

  • Package path or module.
  • Go version (default: latest stable).
  • Concurrency and latency requirements.

Outputs

  • Code that passes `go vet`, `staticcheck`, and `go test -race`.
  • Table-driven tests covering error paths.
  • A shutdown path that drains work and honors context cancellation.

Workflow

1. **Define the contract** — Types and function signatures first. Errors are part of the signature. 2. **Implement the happy path** — Then handle every error explicitly. No `_ = err`. 3. **Bound concurrency** — Every goroutine has an owner, a cancellation path, and a place its error is read. 4. **Test the table** — Cases as data, including the error cases. 5. **Gate** — `go vet ./...`, `staticcheck ./...`, `go test -race ./...`.

Best Practices

  • Accept interfaces, return structs. Define the interface in the consuming package, not the producing one.
  • Wrap errors with context: `fmt.Errorf("load user %s: %w", id, err)`. Wrap once per layer, no more.
  • Pass `context.Context` as the first parameter to anything that does I/O. Never store it in a struct.
  • A goroutine started without a way to stop it is a leak. Use `errgroup.WithContext` for anything fan-out.
  • Do not use `panic` for control flow. It is for programmer error only.
  • Preallocate slices when the size is known: `make([]T, 0, n)`.

Examples

**Bounded fan-out with error propagation:**

func FetchAll(ctx context.Context, ids []string, limit int) ([]User, error) {
    g, ctx := errgroup.WithContext(ctx)
    g.SetLimit(limit)

    users := make([]User, len(ids))
    for i, id := range ids {
        i, id := i, id
        g.Go(func() error {
            u, err := fetch(ctx, id)
            if err != nil {
                return fmt.Errorf("fetch user %s: %w", id, err)
            }
            users[i] = u
            return nil
        })
    }
    if err := g.Wait(); err != nil {
        return nil, err
    }
    return users, nil
}

**Table-driven test including failures:**

func TestParseDuration(t *testing.T) {
    tests := map[string]struct {
        in      string
        want    time.Duration
        wantErr error
    }{
        "seconds":     {in: "30s", want: 30 * time.Second},
        "empty":       {in: "", wantErr: ErrEmptyInput},
        "bad unit":    {in: "5 fortnights", wantErr: ErrUnknownUnit},
    }
    for name, tc := range tests {
        t.Run(name, func(t *testing.T) {
            got, err := ParseDuration(tc.in)
            if !errors.Is(err, tc.wantErr) {
                t.Fatalf("err = %v, want %v", err, tc.wantErr)
            }
            if got != tc.want {
                t.Errorf("got %v, want %v", got, tc.want)
            }
        })
    }
}

Notes

  • `go test -race` catches data races only on code paths it actually executes. Race-test the concurrent paths deliberately.
  • Since Go 1.22, loop variables are per-iteration; the `i, id := i, id` shadowing above is redundant on 1.22+ but harmless and still required on older versions.
  • Generics are useful for containers and constraints, not as a substitute for interfaces.
Read more
@nimadorostkar
Ships withclaude-skills-collection

A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.

Stars on GitHub

Momentum

stars in total
34
Star history of nimadorostkar/Claude-Skills-collection on GitHub, a chart by star-history.com

Other skills on claude-skills-collection.

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills13d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc2w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react4d252k
@facebook@facebookInstall Skill

Questions about go.

Which coding agents can use go?
go installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.