cxuu avatar

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-code

Installs 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 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

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
1factory-ai avatarno-use-effectfactory-ai/factory-pluginsEnforce the no-useEffect rule when writing or reviewing React code. ACTIVATE when writing React components, refactoring existing useEffect calls, reviewing PRs 1.1Kskills.sh installs
2dodopayments avatarsubscription-integrationdodopayments/skillsGuide for managing recurring subscriptions after checkout, including trials, lifecycle states, plan changes, cancellation, failed-payment recovery, proration, m1Kskills.sh installs
3inference-sh avatarpitch-deck-visualsinference-sh/skillsInvestor pitch deck structure with slide-by-slide framework, visual design rules, and data presentation. Covers the 12-slide framework, chart types, team slides1Kskills.sh installs
4netlify avatarnetlify-cli-and-deploynetlify/context-and-toolsGuide for using the Netlify CLI and deploying sites. Use when installing the CLI, linking sites, deploying (Git-based or manual), managing environment variables1Kskills.sh installs
5daymade avatarpdf-creatordaymade/claude-code-skillsConvert markdown files to professional PDF documents with proper Chinese font support, theme system, and visual self-check. Use whenever the user asks to create1Kskills.sh installs
6inference-sh avatarlinkedin-contentinference-sh/skillsLinkedIn post writing with hook formulas, formatting rules, and engagement patterns. Covers post types, algorithm signals, character limits, and content pillars1Kskills.sh installs