go-declarations
Skill9 starsChanged 4 months agoMITView on GitHub
Use when declaring or initializing Go variables, constants, structs, or maps. Covers var vs :=, grouped declaration blocks, iota enums starting at 1, struct/map/slice composite literals, raw string literals, `any` over `interface{}`, and avoiding shadowed builtins. Apply proactively to any new struct, const block, or top-level var, even if the user did not ask about declaration style. Does not cover identifier naming (see go-naming).
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- cxuu/golang-skillsedited, first seen Jun 20, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- cxuu/golang-skills★ 16515% same
Wrote their own version · 0
None found.
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-defensiveSkill
- go-documentationSkill
- go-error-handlingSkill
- go-functional-optionsSkill
- go-functionsSkill
- 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
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 71
Use plain iota only when the zero value is the sensible default (e.g., LogToStdout = iota).
- Very specific: line 80
&T{...}overnew(T): when you want a pointer. - Distinctive: line 88
Test tables with ≤3 fields may use positional literals when the meaning is obvious.
- Distinctive: line 102
Use backticks to avoid escape gymnastics:
≈ “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 Declarations and Initialization
Pick the simplest declaration form that expresses your intent: scope variables tightly, group related declarations, and let the zero value do its job.
Core Rules
:=for locals with values;varfor intentional zero values or top-level declarations.- Group related declarations in parenthesized blocks. Separate unrelated ones into distinct blocks.
- Start enums at
iota + 1so the zero value is "invalid/unset" — unless zero is genuinely meaningful. - Initialize structs with field names. Omit zero-value fields; let defaults speak.
- Use
any, notinterface{}, in all new code. - Never shadow builtins (
len,cap,error,new,make,copy,any,nil, ...).
Decision: var vs :=
| Context | Use | Example |
| Package-level | var (always) | var startTime = time.Now() |
| Local with computed value | := | s := "foo" |
| Local zero-value, intentional | var | var filtered []int |
| Declared type differs from RHS | var T = expr | var e error = f() |
Read references/scope-and-shadowing.md when fighting subtle bugs caused by
:=redeclaring an outer variable.
Group Related Declarations
// Bad
const a = 1
const b = 2
// Good
const (
a = 1
b = 2
)Inside functions, group adjacent vars even if loosely related:
var (
caller = c.name
format = "json"
timeout = 5 * time.Second
)Constants and iota
Zero is the default; reserve it for "uninitialized" by starting enums at iota + 1:
type Operation int
const (
Add Operation = iota + 1 // 1
Subtract // 2
Multiply // 3
)Use plain iota only when the zero value is the sensible default (e.g., LogToStdout = iota).
Read references/iota-and-literals.md for bitmask enums,
String()methods, raw strings, and composite-literal formatting.
Initializing Structs
- Always use field names. Positional struct literals break on field reordering and are caught by
go vet. - Omit zero-value fields — clarity beats explicit zeros.
var u Userfor a zero-value struct (notu := User{}).&T{...}overnew(T)when you want a pointer.
u := User{Name: "Ada", Email: "ada@example.com"}
sptr := &Config{Timeout: 5 * time.Second}
var empty Buffer // zero value, ready to useTest tables with ≤3 fields may use positional literals when the meaning is obvious.
Initializing Maps
| Scenario | Use | Example |
| Empty, will be populated | make(map[K]V) | m := make(map[string]int) |
| Nil, lazily allocated | var | var m map[string]int |
| Known entries up front | Literal | m := map[string]int{"a": 1} |
make signals "initialized but empty" — different from a nil map (which panics on write). Provide a size hint when the count is known: make(map[K]V, n).
Raw String Literals
Use backticks to avoid escape gymnastics:
// Bad
re := "^\\s*name:\\s*\"(.*)\""
// Good
re := `^\s*name:\s*"(.*)"`Ideal for regex, SQL, JSON, and multi-line text.
any, not interface{}
// Old
func Print(v interface{}) { ... }
// New
func Print(v any) { ... }any is an alias for interface{} since Go 1.18 — same type, less noise.
Don't Shadow Builtins
The predeclared identifiers (error, string, len, cap, append, copy, new, make, close, delete, panic, recover, any, true, false, nil, iota) are not reserved words — Go lets you shadow them. Don't.
// Bad — shadows the builtin error type
var error string
// Good
var errorMessage stringgo vet catches the most common cases.
Read references/structs-and-tags.md when designing struct fields that cross a serialization boundary (JSON, YAML, protobuf), embedding types, or formatting many-field literals.
Anti-Patterns
| Anti-pattern | Why it hurts | Do this instead |
u := User{} for a zero value | Misleads readers into expecting non-defaults | var u User |
new(T) then assign fields | Two-step where one works | &T{Field: v} |
| Positional struct literals (>3 fields) | Silent breakage on field reordering | Use field names |
iota starting at 0 for an enum | Zero value collides with a real case | iota + 1 |
var m map[string]int then m[k] = v | Panic on nil map write | m := make(map[string]int) |
| Hand-escaped JSON or regex strings | Hard to read, easy to mistype | Raw string literal |
interface{} in new code | Verbose, outdated | any |
Verification Checklist
- Top-level declarations use
var/const; locals use:=unless zero-value is intended - Related
const/var/typeare in grouped blocks - Enums start at
iota + 1(or the zero value is explicitly meaningful) - Struct literals use field names; zero-value fields are omitted
- Maps that will be written to are constructed with
make - No builtins shadowed (
error,len,cap, ...) anyused instead ofinterface{}
References
- references/scope-and-shadowing.md — variable scope,
:=redeclaration rules, shadowing traps - references/iota-and-literals.md — iota patterns, bitmasks, raw strings, composite literals
- references/structs-and-tags.md — struct initialization, field tags, embedding
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.

