Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cxuu avatar

Go Declarations

  • 659 installs
  • 137 repo stars
  • Updated June 20, 2026
  • cxuu/golang-skills

go-declarations is a Claude Code skill that enforces idiomatic Go variable, constant, struct, map, and iota enum declarations for developers writing backend Go 1.18+ code with consistent initialization style.

About

go-declarations is a Go style skill from cxuu/golang-skills focused on declaration and initialization idioms. It routes agents to references/SCOPE.md for var versus :=, if-init narrowing, and composite literal formatting, plus references/IOTA.md for constant blocks and enumerated types. Examples use any instead of interface{}, requiring Go 1.18+. Developers reach for go-declarations when creating new structs, const blocks, or maps even if they do not explicitly ask about style, because the skill prevents scope leaks and non-idiomatic patterns before review. It pairs with go-naming for identifiers but owns declaration mechanics exclusively.

  • Enforces var vs := rules including top-level, zero-value intent, and type-expression mismatch cases
  • Guides narrow scoping with if-init statements and reduces variable lifetime
  • Formats composite literals with keyed fields and consistent struct/map initialization
  • Designs clean iota-based enums and replaces interface{} with any (Go 1.18+)
  • References 6 focused SCOPE, IOTA, INITIALIZATION, LITERALS, STRUCTS, and SHADOWING guides

Go Declarations by the numbers

  • 659 all-time installs (skills.sh)
  • Ranked #563 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cxuu/golang-skills --skill go-declarations

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs659
repo stars137
Last updatedJune 20, 2026
Repositorycxuu/golang-skills

When should Go code use var versus :=?

Get consistent, idiomatic Go declarations and initializations every time they create variables, constants, structs, maps, or iota enums.

Who is it for?

Go backend developers writing new structs, maps, or const blocks who want consistent declaration style aligned with Go 1.18+ idioms.

Skip if: Developers needing Go naming conventions, package layout guidance, or concurrency patterns outside declaration and initialization syntax.

When should I use this skill?

User writes Go variables, constants, structs, maps, iota enums, or asks about var versus := and if-init scope.

What you get

Idiomatic Go declarations with correct scope, composite literals, and iota enum constant blocks.

  • idiomatic Go declarations
  • iota enum blocks
  • scoped variable initializations

By the numbers

  • Includes references/SCOPE.md and references/IOTA.md guidance files
  • Examples require Go 1.18+ for any instead of interface{}

Files

SKILL.mdMarkdownGitHub ↗

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

// Good
const (
    a = 1
    b = 2
)

Inside functions, group adjacent vars even if unrelated:

var (
    caller  = c.name
    format  = "json"
    timeout = 5 * time.Second
)

---

Constants and iota

Start enums at one so the zero value represents invalid/unset:

const (
    Add Operation = iota + 1
    Subtract
    Multiply
)

Use zero when the default behavior is desirable (e.g., LogToStdout).

---

Variable Scope

Use if-init to limit scope when the result is only needed for the error check:

if err := os.WriteFile(name, data, 0644); err != nil {
    return err
}

Don't reduce scope if it forces deeper nesting or you need the result outside the if. Move constants into functions when only used there.

---

Initializing Structs

  • Always use field names (enforced by go vet). Exception: test tables

with ≤3 fields.

  • Omit zero-value fields — let Go set defaults.
  • Use `var` for zero-value structs: var user User not user := User{}
  • Use `&T{}` over `new(T)`: sptr := &T{Name: "bar"}

---

Composite Literal Formatting

Use field names for external package types. Match closing brace indentation with the opening line. Omit repeated type names in slice/map literals (gofmt -s).

---

Initializing Maps

ScenarioUseExample
Empty, populated latermake(map[K]V)m := make(map[string]int)
Nil declarationvarvar m map[string]int
Fixed entries at initLiteralm := map[string]int{"a": 1}

make() visually distinguishes empty-but-initialized from nil. Use size hints when the count is known.

---

Raw String Literals

Use backtick strings to avoid hand-escaped characters:

// Bad
wantError := "unknown name:\"test\""

// Good
wantError := `unknown name:"test"`

Ideal for regex, SQL, JSON, and multi-line text.

---

Prefer any Over interface{}

Go 1.18+: use any instead of interface{} in all new code.

---

Avoid Shadowing Built-In Names

Never use predeclared identifiers (error, string, len, cap, append, copy, new, make, close, delete, panic, recover, any, true, false, nil, iota) as names. Use go vet to detect.

// Bad — shadows the builtin
var error string

// Good
var errorMessage string

---

Related Skills

  • Naming conventions: See go-naming when choosing variable names, constant names, or deciding name length by scope
  • Data structures: See go-data-structures when choosing between new and make, or initializing slices and maps
  • Control flow scoping: See go-control-flow when using if-init, := redeclaration, or avoiding variable shadowing
  • Capacity hints: See go-performance when pre-allocating maps or slices with known sizes

Related skills

How it compares

Use go-declarations for initialization idioms and pair go-naming when identifier naming also needs review.

FAQ

What Go version does go-declarations require?

go-declarations examples use any instead of interface{}, which requires Go 1.18 or newer. The skill covers var, :=, if-init scope, composite literals, and iota enum patterns for backend code.

Does go-declarations cover Go naming rules?

go-declarations focuses on declaration and initialization idioms such as var versus := and iota enums. Naming conventions are handled by the separate go-naming skill in cxuu/golang-skills.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.