mcpbeat Sign in

Go Packages Agent Skill

by cxuu

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

3k tokens
context cost
the whole folder, loaded on every use
3
files
instructions only
0
copies elsewhere
how many repositories repackaged it
136
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/cxuu/golang-skills --skill go-packages

The instruction itself

10 sections, as written by the author

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

| 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

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:

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

Avoid init() where possible. When unavoidable, it must be:

  • Completely deterministic
  • Independent of other init() ordering
  • Free of environment state (env vars, working dir, args)
  • 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)
    }
}

  • 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

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

30k tokens scripts
Changelog Generator
by frostant
×9

Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
MCP Builder
by JayZeeDesign
×7

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

39k tokens
Vercel React Best Practices
by ratacat
×5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification

1k tokens

How to use it

Copy the folder

Take cxuu/go-packages from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.