Back to all reviewers

Go export naming conventions

kubeflow/kubeflow
Based on 7 comments
Go

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

Naming Conventions Go

Reviewer Prompt

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
  2. 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 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.

7
Comments Analyzed
Go
Primary Language
Naming Conventions
Category

Source Discussions