---
name: golang-engineer
description: "Idiomatic Go: goroutines done right, error handling, testing, modules, perf tuning. Senior Go dev as a skill. Writes idiomatic Go — context propagation, error wrapping, channel patterns, table tests, benchmarks. Knows when to reach for stdlib vs third-party."
license: MIT
---

# Golang Engineer

A senior Go engineer in skill form. It writes and reviews idiomatic Go the way an experienced team lead would: correct concurrency, errors that carry context, tests that fail with useful messages, and a sober view of when the standard library already solves the problem. Aimed at backend and platform developers who want code that survives `go vet`, the race detector, and a critical PR review.

## When to use it

- You're wiring up goroutines and want to avoid leaks, deadlocks, or unsynchronized access.
- An incoming request needs cancellation and deadline propagation through several layers.
- You're standing up a new module and want a sane layout, error strategy, and test scaffolding from the start.
- A function is hot in the profiler and you need a benchmark plus a fix backed by numbers.
- You're deciding between `encoding/json`, `database/sql`, `net/http` and a third-party alternative.

## What it does

- **Concurrency:** worker pools, fan-in/fan-out, `select` with `ctx.Done()`, `errgroup.Group` for bounded parallel work, `sync.Once`/`sync.WaitGroup`/`sync.Mutex` placed correctly. Flags goroutine leaks and missing channel closes.
- **Errors:** wraps with `fmt.Errorf("...: %w", err)`, inspects with `errors.Is` / `errors.As`, defines sentinel errors and typed errors where each fits. Discourages naked `panic` in library code.
- **Context:** threads `context.Context` as the first parameter, uses `context.WithTimeout`/`WithCancel`, and avoids stashing request data in context except request-scoped values.
- **Testing:** table-driven tests with subtests via `t.Run`, `t.Parallel()`, golden files, `testing.B` benchmarks, and fuzz targets (`func FuzzX(f *testing.F)`).
- **Tooling:** drives `go test -race`, `go test -bench=. -benchmem`, `go vet`, `go test -cover`, and `pprof` for CPU/heap profiles.

## Usage

```bash
curl -fsSL --create-dirs -o ~/.claude/skills/golang-engineer/SKILL.md https://claudeskil.com/skills/golang-engineer/SKILL.md

# then, in your repo:
"Convert this sequential fetch loop into a bounded worker pool with errgroup,
 honoring the request context, and add a table-driven test."
```

```go
g, ctx := errgroup.WithContext(ctx)
sem := make(chan struct{}, 8) // cap concurrency
for _, u := range urls {
    u := u
    sem <- struct{}{}
    g.Go(func() error {
        defer func() { <-sem }()
        return fetch(ctx, u)
    })
}
err := g.Wait()
```

## Tips & gotchas

- The classic loop-variable capture bug only bites on Go ≤ 1.21; the skill still adds `u := u` unless your `go.mod` declares 1.22+.
- It runs benchmarks with `-benchmem` so allocation counts, not just ns/op, drive optimization decisions.
- It treats a passing test suite without `-race` as unverified for any concurrent code.
- Buffered channels are sized deliberately, never as an accidental "fix" for a synchronization bug.

## FAQ

**Does it pull in heavy dependencies?** No. It defaults to stdlib and reaches for `golang.org/x/...` (e.g. `errgroup`) or well-known libraries only when they clearly earn their place, and says why.

**Will it match my project's conventions?** Yes — it reads your existing packages, `go.mod` version, and error-handling style before generating code.

**Can it explain a profile?** It generates the `pprof` commands and interprets the hot paths, then proposes a benchmark-backed change.
