mit einem Klick
golang-code-style
// Golang code style, formatting and conventions. Use when writing Go code, reviewing style, configuring linters, writing comments, or establishing project standards.
// Golang code style, formatting and conventions. Use when writing Go code, reviewing style, configuring linters, writing comments, or establishing project standards.
Startup / AI-startup CTO who is also a top-tier individual contributor. Two modes: (1) greenfield โ turn fuzzy business intent into a buildable design (brief.md, arch.md, specs/) through conversation; (2) brownfield โ work hands-on inside an existing codebase: investigate, recommend, refactor, write features, debug, ship PRs, update ADRs and plan docs. Trigger when the user wants to build something new ('I want to build', 'help me design', 'ๆๆณๅ', 'ๅธฎๆๆณๆณ่ฟไธชๆไนๅ'), AND trigger when the user invokes /cto on an existing codebase for architecture work, migrations, refactors, debugging, or any senior-IC task they want CTO-level judgment and execution on. Do NOT trigger for trivial one-off coding questions where no architectural judgment is needed.
Golang benchmarking, profiling, and performance measurement. Use when writing, running, or comparing Go benchmarks, profiling hot paths with pprof, interpreting CPU/memory/trace profiles, analyzing results with benchstat, setting up CI benchmark regression detection, or investigating production performance with Prometheus runtime metrics. Also use when the developer needs deep analysis on a specific performance indicator - this skill provides the measurement methodology, while golang-performance provides the optimization patterns.
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.
Golang concurrency patterns. Use when writing or reviewing concurrent Go code involving goroutines, channels, select, locks, sync primitives, errgroup, singleflight, worker pools, or fan-out/fan-in pipelines. Also triggers when you detect goroutine leaks, race conditions, channel ownership issues, or need to choose between channels and mutexes.
Idiomatic context.Context usage in Golang โ creation, propagation, cancellation, timeouts, deadlines, context values, and cross-service tracing. Apply when working with context.Context in any Go code.
Provides CI/CD pipeline configuration using GitHub Actions for Golang projects. Covers testing, linting, SAST, security scanning, code coverage, Dependabot, Renovate, GoReleaser, code review automation, and release pipelines. Use this whenever setting up CI for a Go project, configuring workflows, adding linters or security scanners, setting up Dependabot or Renovate, automating releases, or improving an existing CI pipeline. Also use when the user wants to add quality gates to their Go project.
| name | golang-code-style |
| description | Golang code style, formatting and conventions. Use when writing Go code, reviewing style, configuring linters, writing comments, or establishing project standards. |
| user-invocable | true |
| license | MIT |
| compatibility | Designed for Claude Code or similar AI coding agents, and for projects using Golang. |
| metadata | {"author":"samber","version":"1.1.2","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 |
Community default. A company skill that explicitly supersedes
samber/cc-skills-golang@golang-code-styleskill takes precedence.
Style rules that require human judgment โ linters handle formatting, this skill handles clarity. For naming see samber/cc-skills-golang@golang-naming skill; for design patterns see samber/cc-skills-golang@golang-design-patterns skill; for struct/interface design see samber/cc-skills-golang@golang-structs-interfaces skill.
"Clear is better than clever." โ Go Proverbs
When ignoring a rule, add a comment to the code.
No rigid line limit, but lines beyond ~120 characters MUST be broken. Break at semantic boundaries, not arbitrary column counts. Function calls with 4+ arguments MUST use one argument per line โ even when the prompt asks for single-line code:
// Good โ each argument on its own line, closing paren separate
mux.HandleFunc("/api/users", func(w http.ResponseWriter, r *http.Request) {
handleUsers(
w,
r,
serviceName,
cfg,
logger,
authMiddleware,
)
})
When a function signature is too long, the real fix is often fewer parameters (use an options struct) rather than better line wrapping. For multi-line signatures, put each parameter on its own line.
SHOULD use := for non-zero values, var for zero-value initialization. The form signals intent: var means "this starts at zero."
var count int // zero value, set later
name := "default" // non-zero, := is appropriate
var buf bytes.Buffer // zero value is ready to use
Slices and maps MUST be initialized explicitly, never nil. Nil maps panic on write; nil slices serialize to null in JSON (vs [] for empty slices), surprising API consumers.
users := []User{} // always initialized
m := map[string]int{} // always initialized
users := make([]User, 0, len(ids)) // preallocate when capacity is known
m := make(map[string]int, len(items)) // preallocate when size is known
Do not preallocate speculatively โ make([]T, 0, 1000) wastes memory when the common case is 10 items.
Composite literals MUST use field names โ positional fields break when the type adds or reorders fields:
srv := &http.Server{
Addr: ":8080",
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
Errors and edge cases MUST be handled first (early return). Keep the happy path at minimal indentation:
func process(data []byte) (*Result, error) {
if len(data) == 0 {
return nil, errors.New("empty data")
}
parsed, err := parse(data)
if err != nil {
return nil, fmt.Errorf("parsing: %w", err)
}
return transform(parsed), nil
}
elseWhen the if body ends with return/break/continue, the else MUST be dropped. Use default-then-override for simple assignments โ assign a default, then override with independent conditions or a switch:
// Good โ default-then-override with switch (cleanest for mutually exclusive overrides)
level := slog.LevelInfo
switch {
case debug:
level = slog.LevelDebug
case verbose:
level = slog.LevelWarn
}
// Bad โ else-if chain hides that there's a default
if debug {
level = slog.LevelDebug
} else if verbose {
level = slog.LevelWarn
} else {
level = slog.LevelInfo
}
When an if condition has 3+ operands, MUST extract into named booleans โ a wall of || is unreadable and hides business logic. Keep expensive checks inline for short-circuit benefit. Details
// Good โ named booleans make intent clear
isAdmin := user.Role == RoleAdmin
isOwner := resource.OwnerID == user.ID
isPublicVerified := resource.IsPublic && user.IsVerified
if isAdmin || isOwner || isPublicVerified || permissions.Contains(PermOverride) {
allow()
}
Scope variables to if blocks when only needed for the check:
if err := validate(input); err != nil {
return err
}
When comparing the same variable multiple times, prefer switch:
switch status {
case StatusActive:
activate()
case StatusInactive:
deactivate()
default:
panic(fmt.Sprintf("unexpected status: %d", status))
}
samber/cc-skills-golang@golang-design-patterns skill).context.Context first, then inputs, then output destinations.func FetchUser(ctx context.Context, id string) (*User, error)
func SendEmail(ctx context.Context, msg EmailMessage) error // grouped into struct
range for IterationSHOULD use range over index-based loops. Use range n (Go 1.22+) for simple counting.
for _, user := range users {
process(user)
}
Pass small types (string, int, bool, time.Time) by value. Use pointers when mutating, for large structs (~128+ bytes), or when nil is meaningful. Details
_ "pkg") register side effects (init functions). Restricting them to main and test packages makes side effects visible at the application root, not hidden in library codeUse strconv for simple conversions (faster), fmt.Sprintf for complex formatting. Use %q in error messages to make string boundaries visible. Use strings.Builder for loops, + for simple concatenation.
Prefer explicit, narrow conversions. Use generics over any when a concrete type will do:
func Contains[T comparable](slice []T, target T) bool // not []any
slices and maps standard packages; for filter/group-by/chunk, use github.com/samber/loreflect unless necessaryWhen reviewing code style across a large codebase, use up to 5 parallel sub-agents (via the Agent tool), each targeting an independent style concern (e.g. control flow, function design, variable declarations, string handling, code organization).
Many rules are enforced automatically: gofmt, gofumpt, goimports, gocritic, revive, wsl_v5. โ See the samber/cc-skills-golang@golang-lint skill.
samber/cc-skills-golang@golang-naming skill for identifier naming conventionssamber/cc-skills-golang@golang-structs-interfaces skill for pointer vs value receivers, interface designsamber/cc-skills-golang@golang-design-patterns skill for functional options, builders, constructorssamber/cc-skills-golang@golang-lint skill for automated formatting enforcementsamber/cc-skills-golang@golang-continuous-integration skill for automated AI-driven code review in CI using these guidelines