agentleFS
iyazerskiiyazerski/dev-flows-plugin/skills/go-best-practices/SKILL.md

go-best-practices

Skill0 starsChanged 4 months agoMITView on GitHub

Go rules that linters can't enforce: new Go 1.27 standard library features and subtle pitfalls in interfaces, errors, concurrency, I/O, transactions, and tests. Use when writing, reviewing, refactoring, or debugging Go code (.go files or go.mod).

4 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions4 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 4

    1. baekenough/oh-my-customcode★ 42same name
    2. mduongvandinh/ai-best-practices-skills★ 18same name
    3. ofershap/go-best-practices★ 2same name
    4. xiangxn/claude-skills★ 0same 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 repository5 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When the gopls MCP tools are available, prefer them to text search: go_search to find symbols, go_symbol_references before you change a …

    line 20
  2. Very specific:

    When unsure whether a standard library symbol exists, run go doc pkg.Symbol.

    line 23
  3. Very specific:

    Write benchmarks with for b.Loop().

    line 39
  4. Distinctive:

    Every goroutine needs an owner that stops it and waits for it to exit before shutdown completes.

    line 65

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “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 best practices

This file assumes Go 1.27 or newer, and that the repo's hooks run gofmt, go fix, golangci-lint, and go test -race. It lists only what those tools don't catch. If the repo has no Go hooks, suggest that the user adopt assets/pre-commit-config.yaml and assets/golangci.yml.

Tools

  • Fix a lint instead of silencing it. If a lint is wrong for one line, use //nolint:name // reason on that line.
  • When the gopls MCP tools are available, prefer them to text search: go_search to find symbols, go_symbol_references before you change a definition, go_rename_symbol for renames, and go_diagnostics on edited files.
  • When unsure whether a standard library symbol exists, run go doc pkg.Symbol.

Newer than your training data

  • uuid (uuid.New, uuid.NewV7, uuid.Parse) is in the standard library. Don't add github.com/google/uuid.
  • Methods can have their own type parameters. Use them instead of package-level generic helpers that serve one type.
  • encoding/json/v2 and encoding/json/jsontext are stable. Prefer v2 in new code. Switching an existing import changes behavior with no compile error: names match case-sensitively, duplicate names and invalid UTF-8 fail, nil slices and maps encode as [] and {}, and time.Duration has no default encoding. Keep old wire formats with v1's json.DefaultOptionsV1() or single options like FormatDurationAsNano(true).
  • os.Root confines file access to a directory. Use it for untrusted names instead of filepath.Join plus prefix checks.
  • tool directives in go.mod (go get -tool) replace tools.go files.
  • Write benchmarks with for b.Loop(). go fix doesn't convert b.N loops.
  • GOMAXPROCS follows container CPU limits on its own. Don't add automaxprocs.

Design

  • Define an interface in the package that uses it, with only the methods that package calls. Constructors return concrete types.
  • slices.Clone and maps.Clone are shallow. When a stored or returned value must not share memory with the caller, copy nested slices, maps, and pointers too.
  • A small substring or subslice keeps its whole backing array alive. Copy it with strings.Clone or slices.Clone before storing it long-term.

Errors and I/O

  • The lint config allows unchecked Close and Flush, because that's fine for readers. For writers, check both: return the error, or errors.Join it with the write error.
  • bufio.Scanner fails with bufio.ErrTooLong on lines over 64 KiB. Call sc.Buffer when lines can be longer, and always check sc.Err().
  • json.Decoder.Decode reads one value and ignores what follows. When the input must be a single document, check that the next Decode returns io.EOF, or use json.Unmarshal or v2's UnmarshalRead, which reject trailing data.
  • HTTP handlers shouldn't send internal error text to clients. Log it and return a status with a short message.

Concurrency and context

  • Every goroutine needs an owner that stops it and waits for it to exit before shutdown completes. Stopping without waiting still leaks work.
  • select picks randomly among ready cases, so ctx.Done() has no priority. Check ctx.Err() before starting each unit of work in a loop.
  • With SetLimit, errgroup.Group.Go blocks until a slot is free and ignores the context. Check ctx.Err() before calling it, or use TryGo.
  • context.WithoutCancel drops the deadline too. Detached work needs its own timeout and an owner that waits for it.
  • http.Client.Timeout covers reading the whole body, so it cuts off streaming and long downloads. Use per-request context deadlines there.
  • MaxIdleConnsPerHost defaults to 2. It doesn't cap concurrency, but extra connections are closed instead of reused. Raise it when many concurrent requests go to one host.
  • Inside a transaction, every query must use tx, not db. A stray db call runs outside the transaction and can deadlock when the pool is small. Rollback after Commit returns sql.ErrTxDone, so a deferred Rollback can ignore it.
  • GOMEMLIMIT is a soft target for the Go heap, not a hard cap. Leave headroom for memory outside the Go heap (cgo, mapped files) below the container limit.

Tests

  • In testing/synctest, time advances only when every goroutine in the bubble is durably blocked. Network I/O and mutexes don't count, so use net.Pipe instead of real sockets inside a bubble.

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.