跳到主内容
智客 ZICQ

技能库 智客分类:运维与云 golang-naming

Golang Naming

Go (Golang) 命名常规——涵盖软件包,构造器,构造器,接口,常数,enums,出错,布林克,接收器,获取器/发取器,功能选项,缩写,测试功能,以及子测试名. 写新时使用此技能 Go 代码,审查或重构,在命名选项(New vs NewTypeName, isConnected vs 连接, ErrNotFound vs NotFoundError, StatusReady vs Status Unknown at iota 0)之间选择,辩论Go包名(utils/helpers ant-patters),或询问Go命名最佳做法. 当用户提及 Mixed Caps vs srave_case, All_CAPS 常数, Get- prefix on getters, 或错误字符串外壳时, 也会触发 。 不用于常规 去吧 执行问题不涉及命名决定.

39540 安装量

官方网址:作者主页

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

Go (Golang) 命名常规——涵盖软件包,构造器,构造器,接口,常数,enums,出错,布林克,接收器,获取器/发取器,功能选项,缩写,测试功能,以及子测试名. 写新时使用此技能 Go 代码,审查或重构,在命名选项(New vs NewTypeName, isConnected vs 连接, ErrNotFound vs NotFoundError, StatusReady vs Status Unknown at iota 0)之间选择,辩论Go包名(utils/helpers ant-patters),或询问Go命名最佳做法. 当用户提及 Mixed Caps vs srave_case, All_CAPS 常数, Get- prefix on getters, 或错误字符串外壳时, 也会触发 。 不用于常规 去吧 执行问题不涉及命名决定.

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Go Naming Conventions、Quick Reference、MixedCaps、Avoid Stuttering、Frequently Missed Conventions、Detailed Categories。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/packages-files.md、references/identifiers.md、references/functions-methods.md、references/types-errors.md、references/testing.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Go (Golang) naming conventions — covers packages, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, test functions, and subtest names. Use this skill when writing new Go code, reviewing or refactoring, choosing between naming alternatives (New vs NewTypeName, isConnected vs connected, ErrNotFound vs NotFoundError, StatusReady vs StatusUnknown at iota 0), debating Go package names (utils/helpers anti-patterns), or asking about Go naming best practices. Also trigger when the user mentions MixedCaps vs snake_case, ALL_CAPS constants, Get-prefix on getters, or error string casing. Do NOT use for general Go implementation questions that don't involve naming decisions.

Go Naming ConventionsQuick ReferenceMixedCapsAvoid StutteringFrequently Missed ConventionsDetailed CategoriesCommon MistakesEnforce with LintersCross-References

兼容:Designed for Claude Code, Codex or similar harness, and for projects using Golang. · 许可:MIT · allowed-tools:Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
golang-naming
description
Go (Golang) naming conventions — covers packages, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, test functions, and subtest names. Use this skill when writing new Go code, reviewing or refactoring, choosing between naming alternatives (New vs NewTypeName, isConnected vs connected, ErrNotFound vs NotFoundError, StatusReady vs StatusUnknown at iota 0), debating Go package names (utils/helpers anti-patterns), or asking about Go naming best practices. Also trigger when the user mentions MixedCaps vs snake_case, ALL_CAPS constants, Get-prefix on getters, or error string casing. Do NOT use for general Go implementation questions that don't involve naming decisions.
compatibility
Designed for Claude Code, Codex or similar harness, and for projects using Golang.
allowed-tools
Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent实验字段,支持情况取决于客户端;字段声明本身不会授予工具权限。
许可
MIT
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 5
  • references/packages-files.md
  • references/identifiers.md
  • references/functions-methods.md
  • references/types-errors.md
  • references/testing.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「golang-naming」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-485849b59c029a7d-Golang-Naming.html
请存为 .cursor/skills/golang-naming/SKILL.md 或 .claude/skills/golang-naming/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/samber/cc-skills-golang 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/samber/cc-skills-golang' --list

npx skills add 'https://github.com/samber/cc-skills-golang' --skill 'golang-naming'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版

name: golang-naming description: "Go (Golang) naming conventions — covers packages, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, test functions, and subtest names. Use this skill when writing new Go code, reviewing or refactoring, choosing between naming alternatives (New vs NewTypeName, isConnected vs connected, ErrNotFound vs NotFoundError, StatusReady vs StatusUnknown at iota 0), debating Go package names (utils/helpers anti-patterns), or asking about Go naming best practices. Also trigger when the user mentions MixedCaps vs snake_case, ALL_CAPS constants, Get-prefix on getters, or error string casing. Do NOT use for general Go implementation questions that don't involve naming decisions." user-invocable: true license: MIT compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang. metadata: author: samber version: "1.2.1" 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 paths:

  • "**/*.go"

Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-naming skill takes precedence.

Go Naming Conventions

Go favors short, readable names. Capitalization controls visibility — uppercase is exported, lowercase is unexported. All identifiers MUST use MixedCaps, NEVER underscores.

"Clear is better than clever." — Go Proverbs

"Design the architecture, name the components, document the details." — Go Proverbs

To ignore a rule, just add a comment to the code.

Quick Reference

| Element | Convention | Example | | --- | --- | --- | | Package | lowercase, single word, _test suffix OK for test files | json, http, tabwriter, http_test | | File | lowercase, underscores OK | user_handler.go | | Exported name | UpperCamelCase | ReadAll, HTTPClient | | Unexported | lowerCamelCase | parseToken, userCount | | Interface | method name + -er | Reader, Closer, Stringer | | Struct | MixedCaps noun | Request, FileHeader | | Constant | MixedCaps (not ALL_CAPS) | MaxRetries, defaultTimeout | | Receiver | 1-2 letter abbreviation | func (s *Server), func (b *Buffer) | | Error variable | Err prefix | ErrNotFound, ErrTimeout | | Error type | Error suffix | PathError, SyntaxError | | Constructor | New (single type) or NewTypeName (multi-type) | ring.New, http.NewRequest | | Boolean field | is, has, can prefix on fields and methods | isReady, IsConnected() | | Test function | Test + function name | TestParseToken | | Acronym | all caps or all lower | URL, HTTPServer, xmlParser | | Variant: context | WithContext suffix | FetchWithContext, QueryContext | | Variant: in-place | In suffix | SortIn(), ReverseIn() | | Variant: error | Must prefix | MustParse(), MustLoadConfig() | | Option func | With + field name | WithPort(), WithLogger() | | Enum (iota) | type name prefix, zero-value = unknown | StatusUnknown at 0, StatusReady | | Named return | descriptive, for docs only | (n int, err error) | | Error string | lowercase (incl. acronyms), no punctuation | "image: unknown format", "invalid id" | | Import alias | short, only on collision | mrand "math/rand", pb "app/proto" | | Format func | f suffix | Errorf, Wrapf, Logf | | Test table fields | got/expected prefixes | input string, expected int |

MixedCaps

All Go identifiers MUST use MixedCaps (or mixedCaps). NEVER use underscores in identifiers — the only exceptions are test function subcases (TestFoo_InvalidInput), generated code, and OS/cgo interop. This is load-bearing, not cosmetic — Go's export mechanism relies on capitalization, and tooling assumes MixedCaps throughout.

// ✓ Good
MaxPacketSize
userCount
parseHTTPResponse

// ✗ Bad — these conventions conflict with Go's export mechanism and tooling expectations
MAX_PACKET_SIZE   // C/Python style
max_packet_size   // snake_case
kMaxBufferSize    // Hungarian notation

Avoid Stuttering

Go call sites always include the package name, so repeating it in the identifier wastes the reader's time — http.HTTPClient forces parsing "HTTP" twice. A name MUST NOT repeat information already present in the package name, type name, or surrounding context.

// Good — clean at the call site
http.Client       // not http.HTTPClient
json.Decoder      // not json.JSONDecoder
user.New()        // not user.NewUser()
config.Parse()    // not config.ParseConfig()

// In package sqldb:
type Connection struct{}  // not DBConnection — "db" is already in the package name

// Anti-stutter applies to ALL exported types, not just the primary struct:
// In package dbpool:
type Pool struct{}        // not DBPool
type Status struct{}      // not PoolStatus — callers write dbpool.Status
type Option func(*Pool)   // not PoolOption

Frequently Missed Conventions

These conventions are correct but non-obvious — they are the most common source of naming mistakes:

Constructor naming: When a package exports a single primary type, the constructor is New(), not NewTypeName(). This avoids stuttering — callers write apiclient.New() not apiclient.NewClient(). Use NewTypeName() only when a package has multiple constructible types (like http.NewRequest, http.NewServeMux).

Boolean struct fields: Unexported boolean fields MUST use is/has/can prefix — isConnected, hasPermission, not bare connected or permission. The exported getter keeps the prefix: IsConnected() bool. This reads naturally as a question and distinguishes booleans from other types.

Error strings are fully lowercase — including acronyms. Write "invalid message id" not "invalid message ID", because error strings are often concatenated with other context (fmt.Errorf("parsing token: %w", err)) and mixed case looks wrong mid-sentence. Sentinel errors should include the package name as prefix: errors.New("apiclient: not found").

Enum zero values: Always place an explicit Unknown/Invalid sentinel at iota position 0. A var s Status silently becomes 0 — if that maps to a real state like StatusReady, code can behave as if a status was deliberately chosen when it wasn't.

Subtest names: Table-driven test case names in t.Run() should be fully lowercase descriptive phrases: "valid id", "empty input" — not "valid ID" or "Valid Input".

Detailed Categories

For complete rules, examples, and rationale, see:

  • Packages, Files & Import Aliasing — Package naming (single word, lowercase, no plurals), file naming conventions, import alias patterns (only use on collision to avoid cognitive load), and directory structure.

  • Variables, Booleans, Receivers & Acronyms — Scope-based naming (length matches scope: i for 3-line loops, longer names for package-level), single-letter receiver conventions (s for Server), acronym casing (URL not Url, HTTPServer not HttpServer), and boolean naming patterns (isReady, hasPrefix).

  • Functions, Methods & Options — Getter/setter patterns (Go omits Get so user.Name() reads naturally), constructor conventions (New or NewTypeName), named returns (for documentation only), format function suffixes (Errorf, Wrapf), and functional options (WithPort, WithLogger).

  • Types, Constants & Errors — Interface naming (Reader, Closer suffix with -er), struct naming (nouns, MixedCaps), constants (MixedCaps, not ALL_CAPS), enums (type name prefix like StatusReady), sentinel errors (ErrNotFound variables), error types (PathError suffix), and error message conventions (lowercase, no punctuation).

  • Test Naming — Test function naming (TestFunctionName), table-driven test field conventions (input, expected), test helper naming, and subcase naming patterns.

Common Mistakes

| Mistake | Fix | | --- | --- | | ALL_CAPS constants | Go reserves casing for visibility, not emphasis — use MixedCaps (MaxRetries) | | GetName() getter | Go omits Get because user.Name() reads naturally at call sites. But Is/Has/Can prefixes are kept for boolean predicates: IsHealthy() bool not Healthy() bool | | Url, Http, Json acronyms | Mixed-case acronyms create ambiguity (HttpsUrl — is it Https+Url?). Use all caps or all lower | | this or self receiver | Go methods are called frequently — use 1-2 letter abbreviation (s for Server) to reduce visual noise | | util, helper packages | These names say nothing about content — use specific names that describe the abstraction | | http.HTTPClient stuttering | Package name is always present at call site — http.Client avoids reading "HTTP" twice | | user.NewUser() constructor | Single primary type uses New() — user.New() avoids repeating the type name | | connected bool field | Bare adjective is ambiguous — use isConnected so the field reads as a true/false question | | "invalid message ID" error | Error strings must be fully lowercase including acronyms — "invalid message id" | | StatusReady at iota 0 | Zero value should be a sentinel — StatusUnknown at 0 catches uninitialized values | | "not found" error string | Sentinel errors should include the package name — "mypackage: not found" identifies the origin | | userSlice type-in-name | Types encode implementation detail — users describes what it holds, not how | | Inconsistent receiver names | Switching names across methods of the same type confuses readers — use one name consistently | | snake_case identifiers | Underscores conflict with Go's MixedCaps convention and tooling expectations — use mixedCaps | | Long names for short scopes | Name length should match scope — i is fine for a 3-line loop, userIndex is noise | | Naming constants by value | Values change, roles don't — DefaultPort survives a port change, Port8080 doesn't | | FetchCtx() context variant | WithContext is the standard Go suffix — FetchWithContext() is instantly recognizable | | sort() in-place but no In | Readers assume functions return new values. SortIn() signals mutation | | parse() panicking on error | MustParse() warns callers that failure panics — surprises belong in the name | | Mixing With*, Set*, Use* | Consistency across the codebase — With* is the Go convention for functional options | | Plural package names | Go convention is singular (net/url not net/urls) — keeps import paths consistent | | Wrapf without f suffix | The f suffix signals format-string semantics — Wrapf, Errorf tell callers to pass format args | | Unnecessary import aliases | Aliases add cognitive load. Only alias on collision — mrand "math/rand" | | Inconsistent concept names | Using user/account/person for the same concept forces readers to track synonyms — pick one name |

Applying these fixes means renaming existing identifiers — → See samber/cc-skills-golang@golang-gopls skill to do it safely: its rename updates every call site across the workspace and refuses a rename that would break interface satisfaction, which a grep/sed or manual Edit-based rename silently misses.

Enforce with Linters

Many naming convention issues are caught automatically by linters: revive, predeclared, misspell, errname. See samber/cc-skills-golang@golang-lint skill for configuration and usage.

Cross-References

  • → See samber/cc-skills-golang@golang-code-style skill for broader formatting and style decisions
  • → See samber/cc-skills-golang@golang-structs-interfaces skill for interface naming depth and receiver design
  • → See samber/cc-skills-golang@golang-lint skill for automated enforcement (revive, predeclared, misspell, errname)
  • → See samber/cc-skills-golang@golang-gopls skill for safe rename when applying a naming fix
  • → See samber/cc-skills-golang@golang-refactoring skill for how to apply a rename safely at scale (gopls Rename/Inline, blast-radius mapping, staged PR workflow) once you've decided what to rename identifiers to

相关技能

运维与云

Docker Essentials

用于容器管理,图像操作,调试的基本道克命令和工作流程.

运维与云

Find Skills

从开放的代理技能生态系统中发现并安装技能. 使用时:(1)用户问"我如何做X",X可能拥有现有技能,(2)用户说"为X找到技能"或"是否为X有技能",(3)用户问"你能否做X",X是专门能力,(4)用户想扩展代理能力,(5)用户想搜索工具,模板,或工作流程,(6)用户提到他们希望…

运维与云

Azure Diagnostics

Azure上使用AppLens,AzureMonitor,资源健康,安全分型的调试Azure生产问题. 当:调试生产问题,故障解答应用服务,应用服务高CPU,应用服务部署失败,故障解答容器应用,故障解答功能,故障解答AKS,VM RDP,Linux SSH,VM黑屏幕,无法连接到…

运维与云

Azure Prepare

准备 azd 用于部署的Azure项目:为Azure开发者CLI(azd)工作流程生成azure.yaml,基础设施(Bicep/Terraform)和多克文件. 仅当用户明确想要使用 azd 作为部署工具时使用, 或项目已经有一个 azure 。 雅姆尔文件。 不使用: 非az…