AGENT SKILL

go-naming

Use when naming Go packages, types, functions, methods, variables, constants, or receiver names, including new types and exported APIs. Package organization belongs to go-packages.

License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 7
Forks
2

01 前言 Front Matter

name
go-naming
description
Use when naming Go packages, types, functions, methods, variables, constants, or receiver names, including new types and exported APIs. Package organization belongs to go-packages.
allowed-tools
Bash(bash ${CLAUDE_SKILL_DIR}/scripts/*)

02 资源文件 5

03 SKILL.md 正文

Go Naming Conventions

Resource Routing

  • scripts/check-naming.sh - Run when checking SCREAMING_SNAKE_CASE constants, Get-prefixed methods with no parameters, generic package names, or receivers named this/self.
  • scripts/check-naming-ast.go - Implementation helper built and run by check-naming.sh; not run or read directly.
  • references/IDENTIFIERS.md - Read for the conventions themselves — package, interface, receiver, constant, initialism, getter and type-suffix names — when a choice for an exported identifier or package-level symbol is in doubt.
  • references/REPETITION.md - Read when names repeat package, receiver, type, or local context.
  • references/VARIABLES.md - Read when choosing local variable names, receiver names, or loop identifiers.

Core Principle

A name is read where it is used, never where it is declared: it does not repeat the package, the receiver, or the surrounding context, and its length grows with the distance between declaration and use. Go names are shorter than in most languages. The reader knows the conventions — MixedCaps, lowercase packages, -er interfaces, short consistent receivers, no Get prefix, initialisms in one case — so this skill carries the decisions and references/ the rules. A package name is short, lowercase, and a single word; layer directories take the plural layer names handlers, services, repositories, models.


Error Names

Normative: Sentinel errors are ErrNotFound when exported and errNotFound when not; error types end in Error (NotFoundError), never ErrNotFoundError. errname in the lint baseline enforces the Err/err prefix and the Error suffix; it accepts ErrNotFoundError, so a name with both is a review item.


Where Review Sends Names Back

  • Repetition against context. widget.New() not widget.NewWidget(); p.Name() not p.ProjectName(); in package sqldb, Connection not DBConnection. A generic package name — util, common, helper, and the rest of the list — is a finding; name the package for what it provides (httpauth, stringutil). REPETITION.md has the cases.
  • _ prefix on unexported globals (Uber only; Google style does not use it): new code writes defaultPort, not _defaultPort, including new code with no neighbor to match. Only a package that already prefixes its globals keeps doing so (VARIABLES.md).
  • Type in the name. users not userSlice, name not nameString; when functions differ only by type, the type goes at the end (ParseInt, ParseInt64).
  • A predeclared identifier as a name. error, string, len, cap, append, copy, new, make as a variable, parameter, or type name compiles and hides the built-in for the rest of the scope (predeclared in the gate reports it); SHADOWING.md owns detection.

Validation

Validation: bash <installed-skill-dir>/scripts/check-naming.sh, run from the project, reports the four patterns its Resource Routing line names. Error names are errname's, and revive exported reports a type or function whose name starts with the package's (widget.WidgetThing), both in the go-linting gate; widget.NewWidget and the rest of the repetition above have no check. Run the script once at the end of the task, beside that gate, which does not run it.

Related Skills

04 同仓库更多 Skills

h0rn3t
h0rn3t/golang-skills

go-troubleshooting

Use when investigating a bug or ticket in a Go service whose cause is unknown — wrong or missing results, tenant-specific behavior, a regression, stage/prod/CI differences, a panic, hang, deadlock, leak, unexplained CPU/RSS growth, or a flaky test. Also use for pasted stack traces, profiles, logs, or requests to find a Go issue's root cause, even without the word debug. Does not cover rewriting ticket text, implementing an already-diagnosed fix alone (use its topic skill), or optimizing a known bottleneck (see go-performance).

★ 7
h0rn3t
h0rn3t/golang-skills

go-testing

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

★ 7
h0rn3t
h0rn3t/golang-skills

go-style-core

Use when resolving Go style or language mechanics such as formatting, nesting, declarations, initialization, scope, shadowing, loops, switches, or enum zero values. API design, naming, errors, and tests have specialized skills.

★ 7
h0rn3t
h0rn3t/golang-skills

go-security

Use when writing or reviewing Go code that touches untrusted input, secrets, or credentials — SQL, shell, or template injection, path traversal, SSRF, cookies and security headers, password hashing, TLS settings, token comparison, or what may appear in a log line. Also use when a handler accepts a file name, URL, or command argument from a client, or when asked to find "vulnerabilities", even if the user never says "security". Does not cover the os.Root and crypto/rand mechanics (see go-defensive) or the dependency CVE scan in the gate (see go-linting).

★ 7
h0rn3t
h0rn3t/golang-skills

go-resilience

Use when handling Go dependency failures or overload with retries, backoff/jitter, budgets, idempotency, duplicate delivery, circuit breakers, bulkheads, rate limits, backpressure, or degradation. Unknown root causes belong to go-troubleshooting.

★ 7
h0rn3t
h0rn3t/golang-skills

go-performance

Use when optimizing slow or performance-critical Go code, allocations, string concatenation in loops, or benchmarks. Also use when writing or reviewing a cache, including implementing one from a stub — its key, its expiry, and how a miss loads. Concurrent code patterns belong to go-concurrency.

★ 7