Skip to content
Back to skills

Writing Go

ASecurity

Check `go.mod` (`go` and `toolchain` lines) and CI before using version-gated APIs. Project conventions win over these defaults.

  • 36 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 6, 2026
ai-agentstypescriptpythonrustgoshelltestingapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned September 29, 2026

npx -y skills add alexei-led/cc-thingz --skill writing-go --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Go?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing Go
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/alexei-led-writing-go-52762b31/badge)](https://www.skillsdirectory.com/skills/alexei-led-writing-go-52762b31)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
{"description":"Idiomatic Go development. Use when writing Go code, designing APIs, reviewing Go implementations, or changing Go tests. Follow the module's target Go version. Prefer stdlib, concrete types, explicit errors, goroutine ownership, fast feedback, and behavior tests. NOT for Python, Rust, TypeScript, shell scripts, or infra-only work.","name":"writing-go"}
---

# Go Development

Check `go.mod` (`go` and `toolchain` lines) and CI before using version-gated APIs. Project conventions win over these defaults.

## Defaults

- Stdlib first: `net/http`, `testing`, `flag`, `log/slog`. Add a module only for a concrete requirement.
- Concrete types in domain code. Consumers own small private interfaces; producers return concrete types.
- Keep HTTP, CLI, database, and vendor SDK types out of domain packages. Map errors to status, exit code, or retry at the edge.
- New binaries: `cmd/<name>` plus `internal/`. Use `pkg/` only for code meant for external import.
- Avoid package stutter: `user.Store`, not `user.UserStore`.
- Doc comments on exported names start with the identifier and end with a period.
- Every goroutine has an owner, a cancellation path, and a completion path. Use `errgroup` for errors or shared cancellation when the module already has it.

## Version-Gated

- 1.24+: `t.Context()`, `t.Chdir()`, and `b.Loop()` in tests.
- 1.25+: `sync.WaitGroup.Go` when no error propagation is needed.
- 1.26+: stdlib `crypto/hpke`; `new(expr)` only when clearer than a local variable or composite literal; self-referential generic constraints belong in generic libraries, not business logic.
- 1.26+: `testing/cryptotest.SetGlobalRandom` swaps process-wide randomness, so never use it in parallel tests.
- `encoding/json/v2` is experimental and exists only under `GOEXPERIMENT=jsonv2`; use it only when the project already builds that way.

## CLIs

- Use the existing framework. Otherwise `flag` for single-command tools, Cobra for large command trees with completions, urfave/cli for small multi-command tools. Skip Viper unless already used.
- Keep `main` thin: it calls `run(ctx, args, stdin, stdout, stderr) error` and maps the result to an exit code. Tests call `run`. Avoid `log.Fatal`; it skips deferred cleanup.
- Config precedence: flag, env, config file, default.

## References

- [testing.md](references/testing.md): read when adding or reshaping tests, or when the test loop is slow.
- [linting.md](references/linting.md): read when changing lint commands or golangci-lint config.

Done when the relevant build/test/lint checks pass on what you changed, or you name each check that did not run and why.

Files in this skill

  • SKILL.md3.3 KB
  • references/cli.md1.9 KB
  • references/linting.md1.4 KB
  • references/patterns.md3.2 KB
  • references/principles.md2 KB
  • references/testing.md3.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.