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
- xiangxn/claude-skillstheir own version, first seen Oct 25, 2026
- baekenough/oh-my-customcodetheir own version, first seen Oct 3, 2026
- ofershap/go-best-practicestheir own version, first seen Feb 21, 2026
- mduongvandinh/ai-best-practices-skillstheir own version, first seen Feb 19, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- baekenough/oh-my-customcode★ 42same name
- mduongvandinh/ai-best-practices-skills★ 18same name
- ofershap/go-best-practices★ 2same name
- 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.
- commitSkill
- distill-chatsSkill
- draft-prSkill
- rust-best-practicesSkill
- second-opinionSkill
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
- Very specific: line 20
When the gopls MCP tools are available, prefer them to text search: go_search to find symbols, go_symbol_references before you change a …
- Very specific: line 23
When unsure whether a standard library symbol exists, run go doc pkg.Symbol.
- Very specific: line 39
Write benchmarks with for b.Loop().
- Distinctive: line 65
Every goroutine needs an owner that stops it and waits for it to exit before shutdown completes.
“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.
Files
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 // reasonon that line. - When the
goplsMCP tools are available, prefer them to text search:go_searchto find symbols,go_symbol_referencesbefore you change a definition,go_rename_symbolfor renames, andgo_diagnosticson 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 addgithub.com/google/uuid.- Methods can have their own type parameters. Use them instead of package-level generic helpers that serve one type.
encoding/json/v2andencoding/json/jsontextare 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{}, andtime.Durationhas no default encoding. Keep old wire formats with v1'sjson.DefaultOptionsV1()or single options likeFormatDurationAsNano(true).os.Rootconfines file access to a directory. Use it for untrusted names instead offilepath.Joinplus prefix checks.tooldirectives ingo.mod(go get -tool) replacetools.gofiles.- Write benchmarks with
for b.Loop().go fixdoesn't convertb.Nloops. GOMAXPROCSfollows container CPU limits on its own. Don't addautomaxprocs.
Design
- Define an interface in the package that uses it, with only the methods that package calls. Constructors return concrete types.
slices.Cloneandmaps.Cloneare 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.Cloneorslices.Clonebefore storing it long-term.
Errors and I/O
- The lint config allows unchecked
CloseandFlush, because that's fine for readers. For writers, check both: return the error, orerrors.Joinit with the write error. bufio.Scannerfails withbufio.ErrTooLongon lines over 64 KiB. Callsc.Bufferwhen lines can be longer, and always checksc.Err().json.Decoder.Decodereads one value and ignores what follows. When the input must be a single document, check that the nextDecodereturnsio.EOF, or usejson.Unmarshalor v2'sUnmarshalRead, 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.
selectpicks randomly among ready cases, soctx.Done()has no priority. Checkctx.Err()before starting each unit of work in a loop.- With
SetLimit,errgroup.Group.Goblocks until a slot is free and ignores the context. Checkctx.Err()before calling it, or useTryGo. context.WithoutCanceldrops the deadline too. Detached work needs its own timeout and an owner that waits for it.http.Client.Timeoutcovers reading the whole body, so it cuts off streaming and long downloads. Use per-request context deadlines there.MaxIdleConnsPerHostdefaults 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, notdb. A straydbcall runs outside the transaction and can deadlock when the pool is small.RollbackafterCommitreturnssql.ErrTxDone, so a deferredRollbackcan ignore it. GOMEMLIMITis 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 usenet.Pipeinstead of real sockets inside a bubble.
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
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.

