An exported identifier is a Go declaration whose name begins with an uppercase letter, making it accessible from other packages. Lowercase declarations remain package-local. Packages therefore define a practical visibility boundary: expose the API users need, while retaining freedom to change internal implementation. section 4.1.1
Apply these package and export rules:
- Export functions, types, variables, constants, or other symbols by starting their names with uppercase letters. section 4.1.1
- Keep implementation details lowercase when they should remain unavailable outside the package. section 4.1.1
- Document every exported symbol with a comment whose sentence starts with the symbol’s name. section 4.1.2
- Keep exported APIs stable for backward compatibility; performance fixes and bug repairs can usually stay behind unexported declarations. section 4.1.1
Exporting a logging type and levels
A library can expose a Logger type and a Level enumeration while keeping other implementation details private:\n\n// Logger is used to log information.\ntype Logger struct {}\n\n// Level represents an available logging level.\ntype Level byte\n\nconst (\n // LevelDebug represents the lowest level of log.\n LevelDebug Level = iota\n LevelInfo\n LevelError\n)\n\nOther packages can use Logger, Level, and the Level constants because their names begin with uppercase letters. section 4.1.1 section 4.1.2
const (
// LevelDebug represents the lowest level of log, mostly used for
// debugging purposes.
LevelDebug Level = iota
// LevelInfo represents a logging level that contains information
// deemed valuable.
LevelInfo
// LevelError represents the highest logging level, only to be used
// to trace errors.
LevelError
)
Inspect the complete exported logging-level declaration, including documentation comments and iota-based constants. section 4.1.2

