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 creating Go packages, organizing imports, managing dependencies, or deciding how to structure Go code into packages. Also use when starting a new Go project or splitting a growing codebase into packages, even if the user doesn't explicitly ask about package
$ npx -y skills add cxuu/golang-skills --skill go-packages --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/go-packagesContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when creating Go packages, organizing imports, managing dependencies, or deciding how to structure Go code into packages. Also use when starting a new Go project or splitting a growing codebase into packages, even if the user doesn't explicitly ask about package
name: go-packages description: Use when creating Go packages, organizing imports, managing dependencies, or deciding how to structure Go code into packages. Also use when starting a new Go project or splitting a growing codebase into packages, even if the user doesn't explicitly ask about package organization. Does not cover naming individual identifiers (see go-naming).
> **When this skill does NOT apply**: For naming individual identifiers within a package, see [go-naming](../go-naming/SKILL.md). For organizing functions within a single file, see [go-functions](../go-functions/SKILL.md). For configuring linters that enforce import rules, see [go-linting](../go-linting/SKILL.md).
Package names should describe what the package provides. Avoid generic names like `util`, `helper`, `common` — they obscure meaning and cause import conflicts.
// Good: Meaningful package names db := spannertest.NewDatabaseFromFile(...) _, err := f.Seek(0, io.SeekStart) // Bad: Vague names obscure meaning db := test.NewDatabaseFromFile(...) _, err := f.Seek(0, common.SeekStart)
Generic names can be used as *part* of a name (e.g., `stringutil`) but should not be the entire package name.
| Question | Action | |----------|--------| | Can you describe its purpose in one sentence? | No → split by responsibility | | Do files never share unexported symbols? | Those files could be separate packages | | Distinct user groups use different parts? | Split along user boundaries | | Godoc page overwhelming? | Split to improve discoverability |
**Do NOT split** just because a file is long, to create single-type packages, or if it would create circular dependencies.
---
Imports are organized in groups separated by blank lines. Standard library packages always come first. Use [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) to manage this automatically.
import (
"fmt"
"os"
"github.com/foo/bar"
"rsc.io/goversion/version"
)**Quick rules:**
| Rule | Guidance | |------|----------| | Grouping | stdlib first, then external. Extended: stdlib → other → protos → side-effects | | Renaming | Avoid unless collision. Rename the most local import. Proto packages get `pb` suffix | | Blank imports (`import _`) | Only in `main` packages or tests | | Dot imports (`import .`) | Never use, except for circular-dependency test files |
---
Avoid `init()` where possible. When unavoidable, it must be:
1. Completely deterministic 2. Independent of other `init()` ordering 3. Free of environment state (env vars, working dir, args) 4. Free of I/O (filesystem, network, system calls)
**Acceptable uses**: complex expressions that can't be single assignments, pluggable hooks (e.g., `database/sql` dialects), deterministic precomputation.
---
Call `os.Exit` or `log.Fatal*` **only in `main()`**. All other functions should return errors.
**Why**: Non-obvious control flow, untestable, `defer` statements skipped.
**Best practice**: Use the `run()` pattern — extract logic into `func run() error`, call from `main()` with a single exit point:
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}---
> **Advisory**: Define flags only in `package main`.
this keeps them testable and reusable
(double-dash, single-char shortcuts) are required
// Good: Flag in main, passed as parameter to library
func main() {
outputDir := flag.String("output_dir", ".", "directory for output files")
flag.Parse()
if err := mylib.Generate(*outputDir); err != nil {
log.Fatal(err)
}
}---
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 declaring or initializing Go variables, constants, structs, or maps — including var vs :=, reducing scope with if-init,…