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
- 参考文档references/IDENTIFIERS.md5.5 KB
- 参考文档references/REPETITION.md2.1 KB
- 参考文档references/VARIABLES.md3.2 KB
- 脚本scripts/check-naming-ast.go9.3 KB
- 脚本scripts/check-naming.sh3.8 KB
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 namedthis/self.scripts/check-naming-ast.go- Implementation helper built and run bycheck-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
ErrNotFoundwhen exported anderrNotFoundwhen not; error types end inError(NotFoundError), neverErrNotFoundError.errnamein the lint baseline enforces theErr/errprefix and theErrorsuffix; it acceptsErrNotFoundError, so a name with both is a review item.
Where Review Sends Names Back
- Repetition against context.
widget.New()notwidget.NewWidget();p.Name()notp.ProjectName(); in packagesqldb,ConnectionnotDBConnection. 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 writesdefaultPort, 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.
usersnotuserSlice,namenotnameString; 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,makeas a variable, parameter, or type name compiles and hides the built-in for the rest of the scope (predeclaredin 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 areerrname's, and reviveexportedreports a type or function whose name starts with the package's (widget.WidgetThing), both in the go-linting gate;widget.NewWidgetand 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
- go-interfaces: pointer versus value receivers; their names are IDENTIFIERS.md's Receiver Names.
- go-packages: splitting packages, import collisions; package names are IDENTIFIERS.md's Package Names.
- go-style-core: shadowing of built-ins, clarity against concision; name length by scope is VARIABLES.md.
04 同仓库更多 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).
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).
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.
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).
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.
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.