go-functions
Skill9 starsChanged 4 months agoMITView on GitHub
Use when organising functions in a Go file, formatting signatures, designing return values, or naming Printf-style helpers. Covers in-file ordering (type → ctor → exported → unexported → utils), multi-line signature shape, naked-parameter clarity, pointer-vs-value receivers, and the `f`-suffix rule. Apply proactively to any new function. Functional options: see go-functional-options.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- cxuu/golang-skillstheir own version, first seen Jun 20, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- cxuu/golang-skills★ 165same 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 repository26 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- go-clean-architectureSkill
- go-code-reviewSkill
- go-code-styleSkill
- go-concurrencySkill
- go-contextSkill
- go-control-flowSkill
- go-databaseSkill
- go-data-structuresSkill
- go-declarationsSkill
- go-defensiveSkill
- go-documentationSkill
- go-error-handlingSkill
- go-functional-optionsSkill
- go-genericsSkill
- go-graphqlSkill
- go-grpcSkill
- go-interfacesSkill
- go-lintingSkill
- go-loggingSkill
- go-namingSkill
- go-observabilitySkill
- go-packagesSkill
- go-performanceSkill
- go-swaggerSkill
- go-testingSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Keep signatures on one line when reasonable: When wrapping, every parameter on its own line with a trailing comma.
- Very specific: line 20
Prefer
%qover%splus manual quoting: when formatting strings for errors and logs. - Very specific: line 76
When a single bool is genuinely binary and obvious from the function name (SetVerbose(true)), it's fine.
- Very specific: line 102
When formatting strings into errors or logs, prefer %q:
- Very specific: line 140
Don't expose a half-built type through a constructor that "always succeeds" but requires Init() afterward.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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.
Files
Go Function Design
A function's surface is read more often than its body. Optimize for the reader: predictable ordering in the file, signatures that scan, no hidden bool flags.
Core Rules
- Order by use, not alphabet. Types → constructors → exported methods → unexported → utilities.
- Keep signatures on one line when reasonable. When wrapping, every parameter on its own line with a trailing comma.
- Never pass
*Interface. Pass the interface value; the underlying data can already be a pointer. - Replace naked
bool/intparameters with named types or add/* name */comments at call sites. - Printf-style functions end in
fsogo vetcan check the format. - Prefer
%qover%splus manual quoting when formatting strings for errors and logs.
File Ordering
type Server struct{ ... }
func NewServer(...) *Server { ... } // constructor next to type
func (s *Server) Start(ctx context.Context) error { ... } // exported
func (s *Server) Stop() error { ... }
func (s *Server) acceptLoop() { ... } // unexported
func parseAddr(s string) (string, error) { ... } // file-local helperRules:
- Types and their constructors sit together at the top.
- Exported methods come before unexported ones.
- File-local helpers go at the bottom.
- Within a section, follow rough call order.
Signature Formatting
// Fits on one line — keep it on one line
func Sum(xs []int) int
// Too long — break with every param on its own line
func (r *Repo) SaveTransaction(
ctx context.Context,
userID string,
tx Transaction,
opts ...SaveOption,
) (string, error) {
...
}The trailing comma is required and gofmt-stable.
Avoid Naked Bool/Int Parameters
// Bad — what does `true` mean?
NewServer(":8080", true, 30, false)
// Better — call-site comments
NewServer(":8080", true /* tls */, 30 /* maxConn */, false /* readonly */)
// Best — named types or options
NewServer(":8080", WithTLS(), WithMaxConn(30))When a single bool is genuinely binary and obvious from the function name (SetVerbose(true)), it's fine.
Read references/signatures.md for return-value styles, naked returns, function-as-parameter formatting, and the variadic-options call-site shape.
Pointers to Interfaces
// Bad
func process(r *io.Reader) { ... }
// Good
func process(r io.Reader) { ... }An interface value already carries a pointer-sized data word. *io.Reader is a pointer to an interface — almost always a mistake.
Printf and Stringer
Functions that accept a format string should end in f:
func Logf(format string, args ...any)go vet then checks that %s, %d, etc. match the argument types.
When formatting strings into errors or logs, prefer %q:
return fmt.Errorf("unknown key %q", key) // unknown key "foo\nbar"%q quotes and escapes; %s plus manual quoting ("key \"" + key + "\"") is fragile.
Read references/printf-and-stringer.md for
%vvs%svs%q, implementingfmt.Stringersafely, avoidingString()infinite recursion, andfmt.Formatter.
Variadic Options at the Call Site
db.Open(addr,
db.WithCache(false),
db.WithLogger(log),
db.WithRetries(3),
)Each option on its own line, trailing comma. Use this layout whenever the call doesn't fit on a single line.
Constructors
A constructor immediately follows its type. Use the short form when no error is possible:
type Counter struct{ n int }
func NewCounter() *Counter { return &Counter{} }Return an error when construction can fail:
func NewClient(addr string) (*Client, error) { ... }Don't expose a half-built type through a constructor that "always succeeds" but requires Init() afterward.
Anti-Patterns
| Anti-pattern | Why it hurts | Do this instead |
| Methods scattered randomly in the file | Hard to navigate | Group by type, exported-first |
| Five-argument wrapped signature with no trailing comma | gofmt keeps reformatting | Trailing comma |
func process(r *io.Reader) | Pointer to interface | Pass io.Reader |
Log(msg string, format bool, ...) | Combines two concerns; vet blind | Separate Log and Logf |
Open(":8080", true, false, 30) | Unreadable booleans | Named options or /* */ comments |
fmt.Errorf("got %s", key) for arbitrary key | Special chars unclear in output | %q |
Returning *MyError (concrete pointer) | Typed-nil interface trap | Return error |
Verification Checklist
- Types appear above their constructors; exported methods above unexported
- Long signatures wrap with one parameter per line and a trailing comma
- No pointer-to-interface parameters
- Bool/int parameters are either obvious from the function name or named with
/* */comments - Functions taking a format string end in
f - Errors and logs use
%qwhen formatting arbitrary strings - Constructors return
(*T, error)when construction can fail — no half-built objects
References
- references/signatures.md — multi-line wrapping, named results, function-typed parameters
- references/printf-and-stringer.md — format verbs,
fmt.Stringer, recursion traps,fmt.Formatter
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.

