Capitalization decides visibility
A name that starts with an upper-case letter is visible outside its package; a lower-case one isn't. So Reader is exported and reader is private to the package. That means you don't pick camelCase or PascalCase by the kind of identifier, as in other languages, but by whether other packages should see it.
The naming table
| Identifier | Convention | Example |
|---|---|---|
| Packages | lower case, single word, no underscores or mixedCaps | bufio, base64 |
| Exported names | MixedCaps | ServeHTTP |
| Unexported names | mixedCaps | parseHeader |
| Getters | the field name, without Get | Owner() |
| Setters | Set plus the field name | SetOwner() |
| One-method interfaces | method name plus -er | Reader, Writer |
| Receivers | one or two letters from the type | c *Client |
MixedCaps, never underscores
Effective Go says Go uses MixedCaps or mixedCaps, rather than underscores, for multi-word names. A Go constant is named the same way: MaxRetries or maxRetries, not MAX_RETRIES.
Initialisms keep a consistent case
Go Code Review Comments says an initialism such as URL is written all upper or all lower: URL or url, never Url. That gives ServeHTTP rather than ServeHttp, and appID rather than appId. When two initialisms meet, write xmlHTTPRequest or XMLHTTPRequest.
Package names shape the other names
A package's name is the last element of its import path: the package imported as "encoding/base64" is named base64. Because callers always write the package name, exported names shouldn't repeat it. The buffered reader in bufio is Reader, not BufReader, and the constructor in package ring is just New.
Short names for short scopes
The Go team prefers short local names: i rather than sliceIndex, c rather than lineCount. The further a name is used from where it's declared, the more descriptive it should be. Receivers should be a one- or two-letter abbreviation of the type, used the same way in every method, never this or self.
Effective Go itself notes that it isn't actively updated and doesn't cover newer features such as generics or modules. Its naming section is still the official reference.
Converting names with Transform Case
Our snake_case, camelCase, PascalCase and CONSTANT_CASE converters treat an acronym as one word, so HTTP server error becomes HttpServerError and http_server_error. Go doesn't use snake_case or CONSTANT_CASE at all, and its initialism rule differs from our output: change ServeHttp to ServeHTTP and userId to userID after converting.
Naming conventions in other languages: Python, Java, C#, Rust, Kotlin, Swift, Dart, PHP. All side by side: 20 languages compared.
Sources
- Effective Go: Names, The Go Authors
- Go Code Review Comments, The Go Authors
Questions
Does Go use snake_case?
No. Effective Go says multi-word names use MixedCaps or mixedCaps rather than underscores.
Should it be userId or userID in Go?userID. Go Code Review Comments says initialisms keep a consistent case, so ID stays ID.
How do you make a Go name public?
Start it with a capital letter. Upper-case names are exported from the package; lower-case names aren't.