Prompt
In Go, the first letter of an identifier (function, variable, struct field, etc.) determines its visibility outside the package:
- Uppercase first letter: The identifier is exported and accessible from other packages
- Lowercase first letter: The identifier is non-exported and only accessible within its package
Always follow these rules:
- Use uppercase for functions intended as public API:
// Exported - can be called from other packages func DisableCullingAnnotationIsSet(meta metav1.ObjectMeta) bool { // implementation } - Use lowercase for functions meant for internal use only:
// Non-exported - only callable within the same package func exists(slice []string, val string) bool { for _, item := range slice { if item == val { return true } } return false } -
Name functions to accurately reflect their purpose and return type. Boolean functions should use predicate naming (is, has, can*).
- For struct fields, use uppercase to allow external access and lowercase to restrict access:
type MetricsExporter struct { Component string // Exported - accessible metricsPort int // Non-exported - internal only } - Use consistent error variable names, typically
errrather than custom names likekfErr,generateErr, etc.
This convention is a critical part of Go’s visibility system and module design - it’s not just a style preference but affects how your code can be used by others.