They even have semantic effect: the visibility of a name outside a package is determined by whether its first character is upper case.
naming conventions
Package names
When a package is imported, the package name becomes an accessor for the contents.import "bytes"
The package name is only the default name for imports; it need not be unique across all source code,
and in the rare case of a collision the importing package can choose a different name to use locally.
Getters
Go doesn’t provide automatic support for getters and setters.
If you have a field called owner
, the getter method should be called Owner
(upper case, exported), not GetOwner
.
A setter function, if needed, will likely be called SetOwner
.
owner := obj.Owner()
if owner != user {
obj.SetOwner(user)
}
Interface names
The one-method interfaces are named by the method name plus an -er suffix or similar modification to construct an agent noun: Reader
, Writer
, Formatter
, CloseNotifier
etc.
MixedCaps
Finally, the convention in Go is to use MixedCaps
or mixedCaps
rather than underscores to write multiword names.