Go Declarations
Go declaration style guide covering var vs :=, iota enums, scope, struct and map initialization, and literal formatting.
- CCM score
- 67 of 100
- skills.sh installs
- 1.1K
- GitHub stars
- 197
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers variable and constant declarations, scoping with if-init, struct and map initialization, composite literal formatting, and shadowing of builtins
- Includes reference files for scope, iota, initialization, literals, structs, and shadowing, with a quick-reference table for choosing
varversus:= - Enforces named struct fields,
iota + 1enums so the zero value stays invalid, andanyoverinterface{}on Go 1.18+ - Designed for Go developers writing new struct, const, or map declarations, and points naming questions to the separate go-naming skill
Install
$ npx -y skills add cxuu/golang-skills --skill go-declarations -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Go Declarations and Initialization
Compatibility: Examples may use
any, which requires Go 1.18+.
Resource Routing
references/SCOPE.md- Read when deciding betweenvar,:=, if-init, and narrow variable scope.references/IOTA.md- Read when designing constants or enum-like values.references/INITIALIZATION.md- Read when initializing structs, maps, zero values, or pointers.references/LITERALS.md- Read for composite literal formatting and keyed-field tradeoffs.references/STRUCTS.md- Read when designing or initializing structs.references/SHADOWING.md- Read when a declaration may shadow a builtin or outer variable.
Quick Reference: var vs :=
| Context | Use | Example |
|---|---|---|
| Top-level | var (always) | var _s = F() |
| Local with value | := | s := "foo" |
| Local zero-value (intentional) | var | var filtered []int |
| Type differs from expression | var with type | var _e error = F() |
Group Similar Declarations
Group related var, const, type in parenthesized blocks. Separate
unrelated declarations into distinct blocks.
// Bad
const a = 1
const b = 2
Details
- Repository
- github.com/cxuu/golang-skills
- Category
- Go
- First seen
- Jun 3, 2026
More from cxuu/golang-skills
All 20- Go Code Review1.9K
- Go Testing1.5K
- Go Error Handling1.4K
- Go Concurrency1.4K
- Go Interfaces1.4K
- Go Linting1.4K
- Go Style Core1.4K
- Go Documentation1.4K
- Go Context1.4K
- Go Performance1.4K
- Go Naming1.4K
- Go Defensive1.4K
- Go Packages1.3K
- Go Functional Options1.3K
- Go Data Structures1.3K
- Go Control Flow1.3K
- Go Logging1.2K
- Go Generics1.1K
- Go Functions1.1K
Similar to Go Declarations
More Gogo-control-flowcxuu/golang-skills1.3K installsGo conditionals, loops, and switch statements with guard clauses, scoped initialization, and blank identifier patterns.
go-documentationcxuu/golang-skills1.4K installsStructured guide for writing Go doc comments, with a validation script for exported symbols and package comments.
golang-structs-interfacessamber/cc-skills-golang42.6K installsGo struct and interface design guide covering composition, embedding, type assertions, and pointer vs value receivers.
golang-namingsamber/cc-skills-golang43.9K installsGo naming conventions covering packages, constructors, errors, booleans, acronyms, and enums, with the rationale for each.
go-code-reviewexistential-birds/beagle206 installsStructured Go review skill that checks idiomatic patterns, error handling, concurrency safety, and version-gated advice from go.mod.