PluginBench
Skill
Pass
Audit score 90

go-packages

cxuu/golang-skills

How to install go-packages

npx skills add https://github.com/cxuu/golang-skills --skill go-packages
Claude Code
Cursor
Windsurf
Cline
Full instructions (SKILL.md)

Source of truth, from cxuu/golang-skills.


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).

Go Packages and Imports

Resource Routing

  • references/IMPORTS.md - Read when grouping imports, using blank imports, dot imports, or import aliases.
  • references/PACKAGE-SIZE.md - Read when splitting packages, avoiding init, structuring main, or designing CLI flags/subcommands.

When this skill does NOT apply: For naming individual identifiers within a package, see go-naming. For organizing functions within a single file, see go-functions. For configuring linters that enforce import rules, see go-linting.

Package Organization

Avoid Util Packages

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.

Package Size

QuestionAction
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

Imports are organized in groups separated by blank lines. Standard library packages always come first. Use goimports to manage this automatically.

import (
    "fmt"
    "os"

    "github.com/foo/bar"
    "rsc.io/goversion/version"
)

Quick rules:

RuleGuidance
Groupingstdlib first, then external. Extended: stdlib → other → protos → side-effects
RenamingAvoid 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()

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.


Exit in Main

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)
    }
}

Command-Line Flags

Advisory: Define flags only in package main.

  • Flag names use snake_case: --output_dir not --outputDir
  • Libraries should accept configuration as parameters, not read flags directly — this keeps them testable and reusable
  • Prefer the standard flag package; use pflag only when POSIX conventions (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)
    }
}

Related Skills

  • Package naming: See go-naming when choosing package names, avoiding stuttering, or naming exported symbols
  • Error handling across packages: See go-error-handling when wrapping errors at package boundaries with %w vs %v
  • Import linting: See go-linting when configuring goimports local-prefixes or enforcing import grouping
  • Global state: See go-defensive when replacing init() with explicit initialization or avoiding mutable globals

Related skills

More from cxuu/golang-skills and the wider catalog.

GO

go-code-review

cxuu/golang-skills

Use when reviewing Go code or checking code against community style standards. Also use proactively before submitting a Go PR or when reviewing any Go code changes, even if the user doesn't explicitly request a style review. Does not cover language-specific syntax — delegates to specialized skills.

1.0k installsAudited
GO

go-testing

cxuu/golang-skills

Use when writing, reviewing, or improving Go test code — including table-driven tests, subtests, parallel tests, test helpers, test doubles, and assertions with cmp.Diff. Also use when a user asks to write a test for a Go function, even if they don't mention specific patterns like table-driven tests or subtests. Does not cover benchmark performance testing (see go-performance).

819 installsAudited
GO

go-linting

cxuu/golang-skills

Use when setting up linting for a Go project, configuring golangci-lint, or adding Go checks to a CI/CD pipeline. Also use when starting a new Go project and deciding which linters to enable, even if the user only asks about "code quality" or "static analysis" without mentioning specific linter names. Does not cover code review process (see go-code-review).

803 installsAudited
GO

go-documentation

cxuu/golang-skills

Use when writing or reviewing documentation for Go packages, types, functions, or methods. Also use proactively when creating new exported types, functions, or packages, even if the user doesn't explicitly ask about documentation. Does not cover code comments for non-exported symbols (see go-style-core).

783 installsAudited
GO

go-performance

cxuu/golang-skills

Use when optimizing Go code, investigating slow performance, or writing performance-critical sections. Also use when a user mentions slow Go code, string concatenation in loops, or asks about benchmarking, even if the user doesn't explicitly mention performance patterns. Does not cover concurrent performance patterns (see go-concurrency).

768 installsAudited
GO

go-error-handling

cxuu/golang-skills

Use when writing Go code that returns, wraps, or handles errors — choosing between sentinel errors, custom types, and fmt.Errorf (%w vs %v), structuring error flow, or deciding whether to log or return. Also use when propagating errors across package boundaries or using errors.Is/As, even if the user doesn't ask about error strategy. Does not cover panic/recover patterns (see go-defensive).

766 installsAudited