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.

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

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/go

Context preview

The summary Claude sees to decide when to auto-load this skill.

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.

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

Get the whole plugin
Stats
27
Stars
3
Forks
Maintained
Maintenance
Python
Language
MIT
License
1mo ago
Last commit
2mo ago
Created

Repo: nimadorostkar/Claude-Skills-collection

Other skills on claude-skills-collection.