
Go Declarations
Handles the mechanical decisions around Go declarations: var versus :=, when to group constants, how iota enums should start at one instead of zero, and why you'd use `&T{}` over `new(T)`. The quick reference tables are genuinely helpful when you're deciding between `make()` and a literal for maps, or remembering that top-level always needs `var`. It pulls from Google and Uber style guides, covers scope reduction with if-init, and pushes `any` over `interface{}` for Go 1.18+. The shadowing section is a nice reminder that `:=` can bite you. If you write Go regularly and want consistent initialization patterns without digging through style guides each time, this consolidates the rules.
- skills.sh installs
- 1.1K
- GitHub stars
- 193
- last updated
- Aug 21, 2026
Install
$ npx -y skills add cxuu/golang-skills --skill go-declarations --agent claude-codeInstalls into .claude/skills of the current project.
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
Sponsors
Details
- Repository
- github.com/cxuu/golang-skills
- Categories
- Documentation, Code Review & Quality, Go
- First seen
- Jun 3, 2026
More from cxuu/golang-skills
All 20- Go Code Review1.8K
- Go Testing1.4K
- Go Error Handling1.3K
- Go Linting1.3K
- Go Concurrency1.3K
- Go Interfaces1.3K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
- Go Data Structures1.3K
- Go Functional Options1.3K
- Go Control Flow1.3K
- Go Logging1.1K
- Go Functions1.1K
- Go Generics1.1K