In Go, the first letter of an identifier (function, variable, struct field, etc.) determines its visibility outside the package: 1. **Uppercase first letter**: The identifier is exported and accessible from other packages
In Go, the first letter of an identifier (function, variable, struct field, etc.) determines its visibility outside the package:
Always follow these rules:
// Exported - can be called from other packages
func DisableCullingAnnotationIsSet(meta metav1.ObjectMeta) bool {
// implementation
}
// 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*).
type MetricsExporter struct {
Component string // Exported - accessible
metricsPort int // Non-exported - internal only
}
err
rather than custom names like kfErr
, 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.
Enter the URL of a public GitHub repository