agentleFS
LucasPcqLucasPcq/wtm/.claude/skills/go-style/SKILL.md

go-style

Skill2 starsChanged 47 days agoMITView on GitHub

How to write Go the way the Go community does — naming, errors, comments and doc comments, readability (paragraphs, function and file shape, parameters), packages and project layout, interfaces, tests, tooling and linters, concurrency — every rule taken from recognized sources (the Go team's Effective Go, Code Review Comments and go.dev docs, the standard library, the Google and Uber Go style guides, Dave Cheney's Practical Go) with its citation. Use this skill whenever you write, review, refactor or explain Go code, in any project — a new function, a test, a package layout, an error message, a doc comment, a linter configuration — and whenever someone asks what is idiomatic in Go, what "the convention" is, or how Go compares with what they know from TypeScript or other languages, even if they don't say "style".

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. els0r/skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository7 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every rule here comes from a source the Go community recognizes, cited in the reference files.

    line 8
  2. Very specific:

    Call the error err and reuse it.

    line 21
  3. Very specific:

    Don't repeat the package in what it exports (bufio.Reader, widget.New).

    line 22
  4. Distinctive:

    Check every error and handle it once: return it or log it, never both.

    line 26
  5. Very specific:

    Add context naming the operation ("open config: %w").

    line 28
  6. Very specific:

    Every exported name has a doc comment: a full sentence that starts with the name (// Run carries out …), "reports whether" for booleans, …

    line 33
  7. Distinctive:

    Use blank lines to break a function into paragraphs, the way paragraphs break a document (Cheney).

    line 38
  8. Very specific:

    Prefer a nil slice to []T{}, useful zero values, field names in composite literals of other packages' types.

    line 41
  9. Distinctive:

    No hard line-length limit.

    line 42
  10. Distinctive:

    Keep interfaces small; accept interfaces, return concrete types (with Google's listed exceptions).

    line 50
  11. Very specific:

    Prefer real implementations, then fakes.

    line 57
  12. Very specific:

    Every goroutine has a known exit and someone waiting for it (sync.WaitGroup, errgroup).

    line 65

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “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

go-style — Go as the community writes it

Every rule here comes from a source the Go community recognizes, cited in the reference files. When sources disagree, follow them in this order — and each reference's last section says which side we took and why:

  1. The Go team: Effective Go, Go Code Review Comments (CRC), Go Doc Comments, module layout, the Go blog, and the standard library's own code.
  2. The Google Go Style Guide (guide, decisions, best practices).
  3. The Uber Go Style Guide.
  4. Recognized authors: Dave Cheney (Practical Go), Rob Pike (Go Proverbs, "Errors are values"), Ben Johnson, Mitchell Hashimoto.

A project's established convention wins over a general rule when the two conflict (consistency inside a codebase is itself a rule of every guide); say so when you follow the project against the community, and propose aligning it when the project rule has no reason left.

The rules that matter most

Naming — references/naming.md

  • A name's length follows the distance between its declaration and its uses: short for a local in a small scope, descriptive for a package-level name.
  • Call the error err and reuse it; give distinct short names only when two errors are alive at once (er/ew in io.copyBuffer). Watch := shadowing inside a block.
  • Don't repeat the package in what it exports (bufio.Reader, widget.New); no util/common/misc packages; initialisms keep one case (URL, ID); no ALL_CAPS constants.
  • Receivers are one or two letters, the same in every method, never this/self; getters are Owner(), not GetOwner().

Errors — references/errors.md

  • Check every error and handle it once: return it or log it, never both.
  • Handle the error first and return; the happy path stays at the left margin, never in an else.
  • Add context naming the operation ("open config: %w"); error strings are lowercase with no final punctuation.
  • Wrap with %w only when callers should inspect the cause — wrapping makes it part of your API; inspect with errors.Is/errors.As, never by string.
  • Errors are opaque by default; export an ErrX sentinel or an XError type only when callers must branch on it. Panic only for programmer errors.

Comments — references/comments.md

  • Every exported name has a doc comment: a full sentence that starts with the name (// Run carries out …), "reports whether" for booleans, the contract not the algorithm.
  • A comment inside a body says why (or how, for a step the code can't make obvious); a block that needs a comment because it does something separate becomes a function named after it.
  • Section separators (// + 76 dashes, then a title line, then a blank line) only in a long file whose declarations fall into named groups; otherwise split the file.

Readability — references/readability.md

  • Use blank lines to break a function into paragraphs, the way paragraphs break a document (Cheney).
  • Return early, reduce nesting, keep variables in the smallest scope.
  • Positional parameters are the norm; reach for an options struct when a function takes many inputs or the call site would be unreadable, and break up several parameters of the same type that a caller could swap (a type, or a struct where it reads better). A struct for two parameters is not a Go convention.
  • Prefer a nil slice to []T{}, useful zero values, field names in composite literals of other packages' types; no mutable globals, no init() doing work.
  • No hard line-length limit; a file is focused enough that a maintainer can tell which file holds something — neither thousands of lines nor many tiny files.

Packages — references/packages.md

  • A package provides one concept and is named after it; merge packages that are always used together; put supporting code in internal/; cmd/ holds mains; there is no pkg/ convention.
  • Layering prevents import cycles; dependencies are passed through constructors and wired by hand in main — no DI framework, no package-level state.

Interfaces — references/interfaces.md

  • The consumer declares the interface, with only the methods it calls; don't define one before it is used or to mock a producer.
  • Keep interfaces small; accept interfaces, return concrete types (with Google's listed exceptions).
  • Pointer receivers when in doubt, and don't mix pointer and value receivers on one type.

Tests — references/testing.md

  • Failures read Func(in) = got, want want; compare with cmp.Diff labelled (-want +got); errors with errors.Is/errors.As.
  • t.Error to keep going, t.Fatal for setup or inside a subtest; helpers call t.Helper() and register teardown with t.Cleanup; use t.TempDir, t.Setenv.
  • Table-driven tests with t.Run; fixtures in testdata/; golden files behind an -update flag.
  • Prefer real implementations, then fakes; the Go team and Google advise against assertion libraries — a project already on testify keeps it consistently (require where the test cannot go on, assert otherwise).

Tooling — references/tooling.md

  • gofmt/goimports are not negotiable; go vet, staticcheck with checks: ["all"] (its defaults leave the naming and doc-comment checks off), go test -race and go mod tidy in CI.
  • golangci-lint with a deliberate set: the standard set + revive exported (doc comments), errorlint, gocritic (diagnostic), unparam, misspell, nolintlint, thelper, usetesting.

Concurrency — references/concurrency.md

  • context.Context is the first parameter, never stored in a struct; always call cancel.
  • Every goroutine has a known exit and someone waiting for it (sync.WaitGroup, errgroup); prefer synchronous functions and let the caller add concurrency.
  • Mutexes use their zero value, are named fields, are never copied; channels are unbuffered or size one unless a reason is written down.

Read next

Open the reference whose subject you are touching before writing or reviewing it; each one is short, lists its rules with their why and their source, and ends with "Where the sources disagree".

ReferenceRead it when
references/naming.mdnaming anything: package, type, function, receiver, variable, error, constant, test
references/errors.mdcreating, returning, wrapping, inspecting or printing an error; deciding to panic
references/comments.mdwriting a doc comment, a package comment, a comment in a body, a section separator, a TODO, a directive
references/readability.mdshaping a function or a file: paragraphs, nesting, parameters, named results, zero values, globals
references/packages.mdcreating or splitting a package, laying out a module, wiring dependencies, structuring an application
references/interfaces.mddeclaring an interface or a port, choosing receivers, embedding, writing a test double
references/testing.mdwriting or reviewing a test, a helper, a fixture, a golden file
references/tooling.mdsetting up or running formatters, vet, staticcheck, golangci-lint, gopls, govulncheck, deadcode
references/concurrency.mdcontexts, goroutines, channels, mutexes, errgroup

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.