$npx -y skills add samber/cc-skills-golang --skill golang-namingGo (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,
| 1 | > **Community default.** A company skill that explicitly supersedes `samber/cc-skills-golang@golang-naming` skill takes precedence. |
| 2 | |
| 3 | # Go Naming Conventions |
| 4 | |
| 5 | Go favors short, readable names. Capitalization controls visibility — uppercase is exported, lowercase is unexported. All identifiers MUST use MixedCaps, NEVER underscores. |
| 6 | |
| 7 | > "Clear is better than clever." — Go Proverbs |
| 8 | > |
| 9 | > "Design the architecture, name the components, document the details." — Go Proverbs |
| 10 | |
| 11 | To ignore a rule, just add a comment to the code. |
| 12 | |
| 13 | ## Quick Reference |
| 14 | |
| 15 | | Element | Convention | Example | |
| 16 | | --- | --- | --- | |
| 17 | | Package | lowercase, single word, \_test suffix OK for test files | `json`, `http`, `tabwriter`, `http_test` | |
| 18 | | File | lowercase, underscores OK | `user_handler.go` | |
| 19 | | Exported name | UpperCamelCase | `ReadAll`, `HTTPClient` | |
| 20 | | Unexported | lowerCamelCase | `parseToken`, `userCount` | |
| 21 | | Interface | method name + `-er` | `Reader`, `Closer`, `Stringer` | |
| 22 | | Struct | MixedCaps noun | `Request`, `FileHeader` | |
| 23 | | Constant | MixedCaps (not ALL_CAPS) | `MaxRetries`, `defaultTimeout` | |
| 24 | | Receiver | 1-2 letter abbreviation | `func (s *Server)`, `func (b *Buffer)` | |
| 25 | | Error variable | `Err` prefix | `ErrNotFound`, `ErrTimeout` | |
| 26 | | Error type | `Error` suffix | `PathError`, `SyntaxError` | |
| 27 | | Constructor | `New` (single type) or `NewTypeName` (multi-type) | `ring.New`, `http.NewRequest` | |
| 28 | | Boolean field | `is`, `has`, `can` prefix on **fields** and methods | `isReady`, `IsConnected()` | |
| 29 | | Test function | `Test` + function name | `TestParseToken` | |
| 30 | | Acronym | all caps or all lower | `URL`, `HTTPServer`, `xmlParser` | |
| 31 | | Variant: context | `WithContext` suffix | `FetchWithContext`, `QueryContext` | |
| 32 | | Variant: in-place | `In` suffix | `SortIn()`, `ReverseIn()` | |
| 33 | | Variant: error | `Must` prefix | `MustParse()`, `MustLoadConfig()` | |
| 34 | | Option func | `With` + field name | `WithPort()`, `WithLogger()` | |
| 35 | | Enum (iota) | type name prefix, zero-value = unknown | `StatusUnknown` at 0, `StatusReady` | |
| 36 | | Named return | descriptive, for docs only | `(n int, err error)` | |
| 37 | | Error string | lowercase (incl. acronyms), no punctuation | `"image: unknown format"`, `"invalid id"` | |
| 38 | | Import alias | short, only on collision | `mrand "math/rand"`, `pb "app/proto"` | |
| 39 | | Format func | `f` suffix | `Errorf`, `Wrapf`, `Logf` | |
| 40 | | Test table fields | `got`/`expected` prefixes | `input string`, `expected int` | |
| 41 | |
| 42 | ## MixedCaps |
| 43 | |
| 44 | 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. |
| 45 | |
| 46 | ```go |
| 47 | // ✓ Good |
| 48 | MaxPacketSize |
| 49 | userCount |
| 50 | parseHTTPResponse |
| 51 | |
| 52 | // ✗ Bad — these conventions conflict with Go's export mechanism and tooling expectations |
| 53 | MAX_PACKET_SIZE // C/Python style |
| 54 | max_packet_size // snake_case |
| 55 | kMaxBufferSize // Hungarian notation |
| 56 | ``` |
| 57 | |
| 58 | ## Avoid Stuttering |
| 59 | |
| 60 | 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. |
| 61 | |
| 62 | ```go |
| 63 | // Good — clean at the call site |
| 64 | http.Client // not http.HTTPClient |
| 65 | json.Decoder // not json.JSONDecoder |
| 66 | user.New() // not user.NewUser() |
| 67 | config.Parse() // not config.ParseConfig() |
| 68 | |
| 69 | // In package sqldb: |
| 70 | type Connection struct{} // not DBConnection — "db" is already in the package name |
| 71 | |
| 72 | // Anti-stutter applies to ALL exported types, not just the primary struct: |
| 73 | // In package dbpool: |
| 74 | type Pool struct{} // not DBPool |
| 75 | type Status struct{} // not PoolStatus — |