Skip to content
cxuu avatar

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
View on GitHub

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 var versus :=
  • Enforces named struct fields, iota + 1 enums so the zero value stays invalid, and any over interface{} 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 -y

Installs 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 between var, :=, 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 :=

ContextUseExample
Top-levelvar (always)var _s = F()
Local with value:=s := "foo"
Local zero-value (intentional)varvar filtered []int
Type differs from expressionvar with typevar _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

Similar to Go Declarations

More Go