| name | go-naming |
| description | Use when naming any Go identifier โ packages, types, functions, methods, receivers, variables, constants, errors, options. Covers MixedCaps, scope-based length, initialism casing, the no-`Get` rule, `-er` interfaces, sentinel `ErrX` vs typed `XError`, and the most commonly missed conventions (constructors, boolean fields, enum zero values, lowercase error strings). Apply proactively whenever new identifiers are introduced, even if the user has not asked about naming. |
| user-invocable | false |
| license | MIT |
| compatibility | Designed for Claude Code or similar AI coding agents. Go 1.0+ for the core rules; iota/enum guidance is version-neutral. |
| metadata | {"author":"muratmirgun","version":"0.1.0","openclaw":{"emoji":"๐ท๏ธ","homepage":"https://github.com/muratmirgun/gophers","requires":{"bins":["go"]},"install":[]}} |
| allowed-tools | Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) |
Go Naming Conventions
Go uses naming to encode visibility (UpperCamelCase = exported, lowerCamelCase = unexported), so naming is load-bearing โ not cosmetic. Names should be short, contextual, and non-repetitive. The package name is always present at the call site; pretending otherwise is the single biggest source of bad Go names.
Core Rules
- MixedCaps only. No underscores, no
SCREAMING_SNAKE_CASE, no kHungarian. Exceptions: test subtests (TestFoo_BadInput), generated code, cgo.
- Capitalization is visibility.
Exported, unexported. Do not invent other conventions.
- No stuttering. The package name is at the call site;
http.HTTPClient is wrong, http.Client is right.
- Scope drives length.
i is fine in a 3-line loop; package-level vars need descriptive names.
- Initialisms keep one case.
userID, HTTPServer, ParseURL โ never userId, HttpServer, ParseUrl.
- Receivers are 1-2 letter abbreviations, consistent across all methods of the type. Never
this/self.
Naming Decision Flow
What are you naming?
โโ Package โ lowercase single word, singular, specific (not util/common/helper)
โโ File โ lowercase, underscores OK (user_handler.go)
โโ Interface โ method + "-er" when single-method (Reader, Closer, Stringer)
โโ Struct/Type โ MixedCaps noun (Request, FileHeader)
โโ Constructor โ New() if package has one primary type; NewThing() if multiple
โโ Constant โ MixedCaps; never ALL_CAPS; role-based not value-based
โโ Enum (iota) โ type-prefix + Unknown/Invalid at position 0
โโ Sentinel error โ ErrXxx (var ErrNotFound = errors.New("..."))
โโ Error type โ XxxError (type PathError struct{})
โโ Boolean field โ is/has/can prefix (isReady, hasPerm)
โโ Getter โ field name only (Owner()), never GetOwner()
โโ Setter โ SetXxx (SetOwner)
โโ Option โ WithXxx (WithLogger, WithPort)
โโ Variant โ WithContext suffix, In suffix (in-place), Must prefix (panics)
โโ Variable โ length proportional to scope distance
Quick Reference Table
| Element | Convention | Example |
|---|
| Package | lowercase, singular | http, tabwriter |
| Exported | UpperCamelCase | ReadAll, HTTPClient |
| Unexported | lowerCamelCase | parseToken, userCount |
| Receiver | 1-2 letters | func (s *Server) |
| Constant | MixedCaps | MaxRetries, defaultTimeout |
| Initialism | uniform case | URL, HTTPServer, xmlParser |
| Sentinel error | Err prefix | ErrNotFound |
| Error type | Error suffix | *PathError |
| Boolean field | is/has/can | isConnected |
| Option func | With + field | WithPort(8080) |
| Format func | f suffix | Errorf, Wrapf |
Frequently Missed Conventions
These are correct but non-obvious โ they account for most naming mistakes in code review.
Constructor: New vs NewThing
If the package exports one primary type, the constructor is New(). Callers write apiclient.New(), not apiclient.NewClient(). Only use NewThing when the package builds several things (http.NewRequest, http.NewServeMux).
Boolean Fields Get a Prefix
Unexported boolean fields use is/has/can. A bare adjective is ambiguous โ is connected a method or a field, a state or a verb past tense?
type Conn struct { isOpen bool }
func (c *Conn) IsOpen() bool { return c.isOpen }
Error Strings Are Fully Lowercase
Including acronyms. Errors get concatenated: fmt.Errorf("parsing token: %w", err) becomes "parsing token: invalid message id". Mid-sentence capitals look wrong. Use "invalid message id" not "invalid message ID".
Sentinel errors should include the package name: errors.New("apiclient: not found").
Enum Zero Value Is a Sentinel
var s Status is silently 0. If 0 is StatusReady, uninitialised values look intentional. Put StatusUnknown (or Invalid) at iota 0.
type Status int
const (
StatusUnknown Status = iota
StatusReady
StatusRunning
)
Subtest Names Are Lowercase Phrases
t.Run("valid id", ...)
t.Run("empty input", ...)
Read references/types-errors-constants.md when naming new struct/interface/enum/error families.
MixedCaps Is Load-Bearing
MaxPacketSize
userCount
parseHTTPResponse
MAX_PACKET_SIZE
max_packet_size
kMaxBufferSize
Avoid Stuttering
The package name is always present at the call site.
type Client struct{}
func New() *User
type Pool struct{}
type Option func()
Read references/identifiers-and-scope.md for receivers, variable scope rules, and import aliasing.
Avoid Built-In Names
Never shadow error, string, len, cap, append, copy, new, make, nil, iota. The compiler allows it; readers and tools do not.
Anti-Patterns
| Mistake | Fix |
|---|
MAX_RETRIES = 3 constant | MaxRetries = 3 โ MixedCaps |
GetName() string getter | Name() string โ Go omits Get |
HttpClient, UserId, ParseUrl | HTTPClient, UserID, ParseURL โ uniform initialism case |
this/self receiver | One-letter abbreviation (s for Server) |
util, common, helpers package | Specific name that describes content (stringutil, httpauth) |
user.NewUser() constructor | user.New() โ drop the type name |
connected bool field | isConnected bool โ prefix reads as a question |
"invalid message ID" error | "invalid message id" โ fully lowercase |
StatusReady at iota 0 | Add StatusUnknown at 0 |
userSlice []User | users []User โ types do not belong in names |
Verification Checklist
Enforce With Linters
Most rules are mechanical and a linter will catch them in CI:
revive โ var-naming, exported, receiver-naming, error-naming.
predeclared โ flags identifiers that shadow built-ins.
errname โ enforces ErrXxx / *XxxError.
misspell โ keeps comments and identifiers consistent.
Add them to .golangci.yml and run golangci-lint run in CI.
References