Loading...
Loading...
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.
npx skill4agent add samber/cc-skills-golang golang-namingCommunity default. A company skill that explicitly supersedesskill takes precedence.samber/cc-skills-golang@golang-naming
"Clear is better than clever." — Go Proverbs"Design the architecture, name the components, document the details." — Go Proverbs
| Element | Convention | Example |
|---|---|---|
| Package | lowercase, single word | |
| File | lowercase, underscores OK | |
| Exported name | UpperCamelCase | |
| Unexported | lowerCamelCase | |
| Interface | method name + | |
| Struct | MixedCaps noun | |
| Constant | MixedCaps (not ALL_CAPS) | |
| Receiver | 1-2 letter abbreviation | |
| Error variable | | |
| Error type | | |
| Constructor | | |
| Boolean field | | |
| Test function | | |
| Acronym | all caps or all lower | |
| Variant: context | | |
| Variant: in-place | | |
| Variant: error | | |
| Option func | | |
| Enum (iota) | type name prefix, zero-value = unknown | |
| Named return | descriptive, for docs only | |
| Error string | lowercase (incl. acronyms), no punctuation | |
| Import alias | short, only on collision | |
| Format func | | |
| Test table fields | | |
MixedCapsmixedCapsTestFoo_InvalidInput// ✓ 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 notationhttp.HTTPClient// 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 PoolOptionNew()NewTypeName()apiclient.New()apiclient.NewClient()NewTypeName()http.NewRequesthttp.NewServeMuxishascanisConnectedhasPermissionconnectedpermissionIsConnected() bool"invalid message id""invalid message ID"fmt.Errorf("parsing token: %w", err)errors.New("apiclient: not found")UnknownInvalidvar s StatusStatusReadyt.Run()"valid id""empty input""valid ID""Valid Input"isGetuser.Name()NewNewTypeNameErrorfWrapfWithPortWithLoggerReaderCloser-erStatusReadyErrNotFoundPathErrorTestFunctionNameinputexpected| Mistake | Fix |
|---|---|
| Go reserves casing for visibility, not emphasis — use |
| Go omits |
| Mixed-case acronyms create ambiguity ( |
| Go methods are called frequently — use 1-2 letter abbreviation ( |
| These names say nothing about content — use specific names that describe the abstraction |
| Package name is always present at call site — |
| Single primary type uses |
| Bare adjective is ambiguous — use |
| Error strings must be fully lowercase including acronyms — |
| Zero value should be a sentinel — |
| Sentinel errors should include the package name — |
| Types encode implementation detail — |
| Inconsistent receiver names | Switching names across methods of the same type confuses readers — use one name consistently |
| Underscores conflict with Go's MixedCaps convention and tooling expectations — use |
| Long names for short scopes | Name length should match scope — |
| Naming constants by value | Values change, roles don't — |
| |
| Readers assume functions return new values. |
| |
Mixing | Consistency across the codebase — |
| Plural package names | Go convention is singular ( |
| The |
| Unnecessary import aliases | Aliases add cognitive load. Only alias on collision — |
| Inconsistent concept names | Using |
revivepredeclaredmisspellerrnamesamber/cc-skills-golang@golang-lintersamber/cc-skills-golang@golang-code-stylesamber/cc-skills-golang@golang-structs-interfacessamber/cc-skills-golang@golang-linter