go-code-review
Use when reviewing Go code or checking code against community style standards. Also use proactively before submitting a Go PR or…
Use when declaring or initializing Go variables, constants, structs, or maps — including var vs :=, reducing scope with if-init, formatting composite literals, designing iota enums, and using any instead of interface{}. Also use when writing a new struct or const block, even if
$ npx -y skills add cxuu/golang-skills --skill go-declarations --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/go-declarationsContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when declaring or initializing Go variables, constants, structs, or maps — including var vs :=, reducing scope with if-init, formatting composite literals, designing iota enums, and using any instead of interface{}. Also use when writing a new struct or const block, even if
name: go-declarations
description: Use when declaring or initializing Go variables, constants, structs, or maps — including var vs :=, reducing scope with if-init, formatting composite literals, designing iota enums, and using any instead of interface{}. Also use when writing a new struct or const block, even if the user doesn't ask about declaration style. Does not cover naming conventions (see go-naming).> Compatibility: Examples may use `any`, which requires Go 1.18+.
| 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 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
)---
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`).
---
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.
---
with ≤3 fields.
---
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`).
---
| Scenario | Use | Example | |----------|-----|---------| | Empty, populated later | `make(map[K]V)` | `m := make(map[string]int)` | | Nil declaration | `var` | `var m map[string]int` | | Fixed entries at init | Literal | `m := map[string]int{"a": 1}` |
`make()` visually distinguishes empty-but-initialized from nil. Use size hints when the count is known.
---
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.
---
Go 1.18+: use `any` instead of `interface{}` in all new code.
---
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
---
AI Agent Skills for writing idiomatic, production-quality Go code. 20 modular skills teach AI coding assistants Go best practices derived from: Google Go Style Guide Effective Go Uber Go Style Guide Go Wiki CodeReviewComments Skills are tuned following
Use when reviewing Go code or checking code against community style standards. Also use proactively before submitting a Go PR or…
Use when writing concurrent Go code — goroutines, channels, mutexes, or thread-safety guarantees. Also use when parallelizing…
Use when working with context.Context in Go — placement in signatures, propagating cancellation and deadlines, and storing values…
Use when writing conditionals, loops, or switch statements in Go — including if with initialization, early returns, for loop…
Use when working with Go slices, maps, or arrays — choosing between new and make, using append, declaring empty slices (nil vs…
Use when hardening Go code at API boundaries — copying slices/maps, verifying interface compliance, using defer for cleanup,…