Loading...
Loading...
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).
npx skill4agent add cxuu/golang-skills go-declarations| Context | Use | Example |
|---|---|---|
| Top-level | | |
| Local with value | | |
| Local zero-value (intentional) | | |
| Type differs from expression | | |
Read references/SCOPE.md when deciding between var and := in complex initialization patterns or multi-return assignments.
varconsttype// Bad
const a = 1
const b = 2
// Good
const (
a = 1
b = 2
)var (
caller = c.name
format = "json"
timeout = 5 * time.Second
)const (
Add Operation = iota + 1
Subtract
Multiply
)LogToStdoutRead references/IOTA.md when designing iota enums with bitmask patterns, byte-size constants, or String() methods.
if err := os.WriteFile(name, data, 0644); err != nil {
return err
}ifRead references/SCOPE.md when working with top-level declarations or choosing between var and := for local variables.
go vetvarvar user Useruser := User{}&T{}new(T)sptr := &T{Name: "bar"}Read references/STRUCTS.md when initializing structs with many fields, building slices of struct pointers, or choosing single-line vs multi-line format.
gofmt -sRead references/INITIALIZATION.md when working with complex composite literals, cuddled braces, or zero-value field decisions.
Read references/LITERALS.md when formatting complex composite literals.
| Scenario | Use | Example |
|---|---|---|
| Empty, populated later | | |
| Nil declaration | | |
| Fixed entries at init | Literal | |
make()// Bad
wantError := "unknown name:\"test\""
// Good
wantError := `unknown name:"test"`anyinterface{}anyinterface{}errorstringlencapappendcopynewmakeclosedeletepanicrecoveranytruefalseniliotago vet// Bad — shadows the builtin
var error string
// Good
var errorMessage stringRead references/SHADOWING.md when debugging issues where := creates new variables that shadow outer scope.
newmake:=