go-functions
Skill7 starsChanged 9 days agoApache-2.0View on GitHub
Use when designing or reviewing Go function APIs, parameters, returns, ordering, Printf helpers, or constructor configuration via parameters, structs, or functional options. Routine body edits alone do not qualify.
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- go-code-refactorSkill
- go-code-reviewSkill
- go-codeSkill
- go-concurrencySkill
- go-contextSkill
- go-databaseSkill
- go-data-structuresSkill
- go-defensiveSkill
- go-documentationSkill
- go-error-handlingSkill
- go-genericsSkill
- go-httpSkill
- go-interfacesSkill
- go-lintingSkill
- go-loggingSkill
- go-namingSkill
- go-packagesSkill
- go-performanceSkill
- go-resilienceSkill
- go-securitySkill
- go-style-coreSkill
- go-testingSkill
- go-troubleshootingSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Follow existing API conventions and preserve signatures unless changing them is in scope.
- Distinctive: line 36
Keep the signature on a single line when possible.
- Very specific: line 48
Add /* name */ comments for ambiguous arguments, or better yet, replace naked bool parameters with custom types.
- Very specific: line 110
Prefer %q over %s with manual quoting when formatting strings for logging or error messages — it safely escapes special characters and …
- Distinctive: line 128
Keep required inputs separate from optional settings.
- Very specific: line 134
Do not change an existing config API merely to introduce With* helpers.
- Distinctive: line 135
Check omitted, explicit zero/nil, and repeated settings against the documented constructor contract.
- Distinctive: line 139
When functional options fit, preserve the repository's convention.
- Very specific: line 159
Add instead: a new function beside the old one, which the old one calls (Open stays, OpenWith(addr string, opts ...Option) is new.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Compatibility: Baseline Go 1.27 (see COMPATIBILITY.md). Returning
iter.Seq[T]requires Go 1.23+.
Resource Routing
references/SIGNATURES.md- Read when designing parameters or signature readability.references/PRINTF-STRINGER.md- Read when using fmt verbs, Stringer, GoStringer, Formatter, or Printf-style function naming.references/OPTIONS-VS-STRUCTS.md- Read when choosing or implementing constructor configuration: config structs, functional options, defaults, validation, and caller ergonomics.
Follow existing API conventions and preserve signatures unless changing them is in scope.
Function Grouping and Ordering
Organize functions in a file by these rules:
- Functions sorted in rough call order
- Functions grouped by receiver
- Exported functions appear first, after
struct/const/vardefinitions NewXxx/newXxxconstructors appear right after the type definition- Plain utility functions appear toward the end of the file
Function Signatures
Keep the signature on a single line when possible. When it must wrap, put all arguments on their own lines with a trailing comma:
func (r *SomeType) SomeLongFunctionName(
foo1, foo2, foo3 string,
foo4, foo5, foo6 int,
) {
foo7 := bar(foo1)
}Add /* name */ comments for ambiguous arguments, or better yet, replace naked
bool parameters with custom types.
ctx context.Context is the first parameter and is never stored;
go-context owns its placement and values.
| Result the caller | Return |
| Consumes once, in order, possibly large or lazily produced | iter.Seq[T] (Go 1.23+); loop form in CONTROL-FLOW.md |
| Stores, indexes, sorts, or re-reads | []T |
Pointers to Interfaces
You almost never need a pointer to an interface. Pass interfaces as values — the underlying data can still be a pointer.
The same holds for every parameter the function reads only as *x: a
string, slice, map, time.Time, or small struct travels by value, never as
a pointer to save a copy. Take a pointer when the callee writes through it,
when the type holds a lock (go vet copylocks reports the copy), or when the
type's methods have pointer receivers — large structs among them, per
RECEIVER-TYPE.md; a type
whose only pointer methods are decoders, such as time.Time, still travels
by value:
func greet(name string) string { ... } // not *string: only read
func drain(q *Queue) { ... } // *Queue: Queue has pointer receiversPrintf and Stringer
Printf-style Function Names
Functions that accept a format string end in f, so the caller knows to pass
one. go vet finds a wrapper that forwards its format to fmt whatever its
name. A function that keeps the format instead (a recorder, a deferred logger)
carries the marker the printf analyzer documents, so a plain go vet ./...
checks its calls:
func Recordf(format string, args ...any) {
if false {
_ = fmt.Sprintf(format, args...) // enable printf checking
}
entries = append(entries, entry{format, args})
}Declare format strings as const when used outside Printf calls. A message
that is not a constant is not a format: from a go 1.24 directive, go vet
reports fmt.Errorf(msg) as non-constant format string.
return errors.New(msg) // or fmt.Errorf("%s", msg); never fmt.Errorf(msg)
t.Fatal(msg) // the non-f form, not t.Fatalf(msg)Prefer %q over %s with manual quoting when formatting strings for logging
or error messages — it safely escapes special characters and wraps in quotes:
return fmt.Errorf("unknown key %q", key) // produces: unknown key "foo\nbar"Constructors and Optional Configuration
Choose the API by how callers configure it; an option count alone does not justify functional options.
| Caller needs | Starting point |
| A few required inputs | Ordinary parameters; meaningful types for ambiguous values |
| Settings usually supplied together, especially internal APIs | Config struct with documented zero values/defaults |
| Public API with independently optional settings and useful defaults | Consider functional options; weigh caller clarity against added types and helpers |
Keep required inputs separate from optional settings. Apply defaults first,
then caller settings, then validate the final configuration, including
interdependent fields. Where the documented zero differs from the default —
Timeout: 0 meaning "no timeout" while unset means 30s — the field is a
pointer (*time.Duration, set with new(0 * time.Second)) or the option
records that it ran; a plain field cannot tell the two apart.
Do not change an existing config API merely to introduce With* helpers.
Check omitted, explicit zero/nil, and repeated settings against the documented
constructor contract. Resolve known mismatches in the code before presenting
it; a caveat does not make a contradictory invariant hold.
When functional options fit, preserve the repository's convention. Without one, start with function-valued options for simple configuration updates; use an interface and concrete option types when callers need capabilities that justify them. Implementation and tradeoffs live in the constructor reference above.
Changing an Exported API
In a module at v1 or later, code compiled against the old API must still compile. These changes look additive and are not:
| Change | What stops compiling |
A parameter appended, variadic included: Open(addr) → Open(addr, opts ...Option) | Calls compile; Open used as a value does not — var dial func(string) (*Conn, error) = Open, a func-typed field, an interface method it satisfied |
| A method added to an exported interface | Every implementation outside the package |
| A slice, map, or func field added to a comparable struct | == on the type and every map keyed by it |
| A field added to a struct callers build unkeyed | T{a, b} literals |
| A method or field added to a type others embed | A type embedding it beside another type with that name: the selector, and since Go 1.27 a keyed literal setting the promoted field (Rec{Label: x}), becomes ambiguous |
Add instead: a new function beside the old one, which the old one calls
(Open stays, OpenWith(addr string, opts ...Option) is new; Query →
QueryContext in database/sql); a constructor new in this release takes a
config struct or ...Option from the start, so later settings are new fields
or With* functions; or a new interface that callers detect with a type
assertion. A change that must break callers is a new major version,
/vN in the module path
(STRUCTURAL.md).
Related Skills
- go-error-handling: error returns in multi-return functions.
- go-naming: function, method, and getter names.
- go-interfaces: consumer-side interface placement and compile-time assertions; option types, the
Optioninterface included, stay here. - go-documentation: constructors, defaults,
With*functions. - go-style-core: general formatting and line length; signature wrapping is owned here.
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.

