golang-benchmark
Golang benchmarking, profiling, and performance measurement. Use when writing, running, or comparing Go benchmarks, profiling hot paths with pprof,…
Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool — especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI
$ npx -y skills add samber/cc-skills-golang --skill golang-cli --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/golang-cliContext preview
The summary Claude sees to decide when to auto-load this skill.
Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool — especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI
name: golang-cli
description: "Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool — especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI unit testing. Also triggers when code uses cobra, viper, or urfave/cli. For cobra-specific APIs → See `samber/cc-skills-golang@golang-spf13-cobra` skill; for viper configuration layering → See `samber/cc-skills-golang@golang-spf13-viper` skill."
user-invocable: true
license: MIT
compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.
metadata:
author: samber
version: "1.3.0"
openclaw:
emoji: "💻"
homepage: https://github.com/samber/cc-skills-golang
requires:
bins:
- go
install: []
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestion
paths:
- "**/*.go"**Persona:** You are a Go CLI engineer. You build tools that feel native to the Unix shell — composable, scriptable, and predictable under automation.
**Modes:**
Use Cobra + Viper as the default stack for Go CLI applications. Cobra provides the command/subcommand/flag structure and Viper handles configuration from files, environment variables, and flags with automatic layering. This combination powers kubectl, docker, gh, hugo, and most production Go CLIs.
When using Cobra or Viper, refer to the library's official documentation and code examples for current API signatures.
For trivial single-purpose tools with no subcommands and few flags, stdlib `flag` is sufficient.
| Concern | Package / Tool | | ------------------- | ------------------------------------ | | Commands & flags | `github.com/spf13/cobra` | | Configuration | `github.com/spf13/viper` | | Flag parsing | `github.com/spf13/pflag` (via Cobra) | | Colored output | `github.com/fatih/color` | | Table output | `github.com/olekukonko/tablewriter` | | Interactive prompts | `github.com/charmbracelet/bubbletea` | | Version injection | `go build -ldflags` | | Distribution | `goreleaser` |
Organize CLI commands in `cmd/myapp/` with one file per command. Keep `main.go` minimal — it only calls `Execute()`.
myapp/ ├── cmd/ │ └── myapp/ │ ├── main.go # package main, only calls Execute() │ ├── root.go # Root command + Viper init │ ├── serve.go # "serve" subcommand │ ├── migrate.go # "migrate" subcommand │ └── version.go # "version" subcommand ├── go.mod └── go.sum
`main.go` should be minimal — see [assets/examples/main.go](assets/examples/main.go).
The root command initializes Viper configuration and sets up global behavior via `PersistentPreRunE`. See [assets/examples/root.go](assets/examples/root.go).
Key points:
Add subcommands by creating separate files in `cmd/myapp/` and registering them in `init()`. See [assets/examples/serve.go](assets/examples/serve.go) for a complete subcommand example including command groups.
See [assets/examples/flags.go](assets/examples/flags.go) for all flag patterns:
Use `MarkFlagRequired`, `MarkFlagsMutuallyExclusive`, and `MarkFlagsOneRequired` for flag constraints.
Provide completion suggestions for flag values.
This ensures `viper.GetInt("port")` returns the flag value, env var `MYAPP_PORT`, or config file value — whichever has highest precedence.
Cobra provides built-in validators for positional arguments. See [assets/examples/args.go](assets/examples/args.go) for both built-in and custom validation examples.
| Validator | Description | | --------------------------- | ------------------------------------ | | `cobra.NoArgs` | Fails if any args provided | | `cobra.ExactArgs(n)` | Requires exactly n args | | `cobra.MinimumNArgs(n)` | Requires at least n args | | `cobra.MaximumNArgs(n)` | Allows at most n args | | `cobra.RangeArgs(min, max)` | Requires between min and max | | `cobra.ExactValidArgs(n)` | Exactly n args, must be in ValidArgs |
Viper resolves configuration values in this order (highest to lowest precedence):
1. **CLI flags** (explicit user input) 2. **Environment variables** (deployment config) 3. **Config file** (persistent settings) 4. **Defaults** (set in code)
See [assets/examples/config.go](assets/examples/config.go) for complete Viper integration includ
AI agent skills are reusable instruction sets that extend your coding assistant with domain-specific expertise, loaded on demand so they don't bloat your context. This repository covers Go-specific skills only (language, testing, security, observability, etc.)
Golang benchmarking, profiling, and performance measurement. Use when writing, running, or comparing Go benchmarks, profiling hot paths with pprof,…
Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments help vs hurt. Use when writing or…
Golang concurrency design — goroutine lifecycle and leak prevention, channels and `select`, channel ownership and direction,…
Idiomatic context.Context usage in Golang — propagation through API boundaries, cancellation, timeouts and deadlines, request-scoped values,…
GitHub Actions CI/CD pipeline configuration for Golang projects — workflow files for test, lint, SAST, coverage and vulnerability-scan jobs, Dependabot and…
Golang data structures — slices (internals, capacity growth, preallocation, slices package), maps (internals, hash buckets, maps package), arrays,…