Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

In Go, an exported identifier is a name (such as a variable, constant, type, function, method, or struct field) that is accessible to code outside of the package in which it is declared. Go does not use access modifier keywords like public, private, or protected. Instead, it relies on a strict lexical rule based on character casing to determine visibility. According to the Go language specification, an identifier is exported if and only if both of the following conditions are met:
  1. The first character of the identifier’s name is a Unicode uppercase letter (Unicode character category Lu).
  2. The identifier is declared in the package block, or it is a field name or method name.
Identifiers that do not meet these criteria (starting with a lowercase letter or an underscore) are unexported and are strictly confined to the package in which they are defined.

Package-Level Declarations

At the package level, the casing of the first letter dictates whether other packages can import and reference the identifier.
package config

// Exported identifiers (Uppercase)
const MaxConnections = 100
var DatabaseURL string
func LoadConfig() {}
type AppConfig struct{}

// Unexported identifiers (Lowercase)
const defaultTimeout = 30
var retryCount int
func parseEnv() {}
type internalState struct{}

Struct Fields and Methods

Visibility rules apply independently to the fields and methods of a type. Exporting a struct type does not automatically export its internal fields or methods. Conversely, an unexported type can possess exported fields and methods. If an instance of an unexported type is exposed to another package (e.g., returned by an exported function), its exported fields and methods remain fully accessible.
package network

// Unexported type
type server struct {
    // Exported field: accessible if a 'server' instance is obtained
    Address string 
    
    // Unexported field: strictly inaccessible outside the 'network' package
    port int       
}

// Exported method: callable from outside the package
func (s *server) Start() error {
    return nil
}

// Exported function exposing an instance of the unexported type
func NewServer() *server {
    return &server{Address: "127.0.0.1", port: 8080}
}
If an external package calls network.NewServer(), it can access the Address field and call the Start() method, even though the server type itself is unexported.

Interface Methods

Go fully supports declaring unexported methods within an exported interface. Because external packages cannot see or implement the unexported method, this mechanically restricts the interface so that it can only be implemented by types defined within the declaring package.
package storage

// Exported interface
type Repository interface {
    // Exported methods
    Save(data []byte) error
    Fetch(id string) ([]byte, error)
    
    // Unexported method
    // External packages can use Repository, but cannot implement it.
    internalLock() 
}

Lexical Edge Cases

  • Acronyms: Go conventions dictate that acronyms should be entirely uppercase (e.g., HTTP, URL) if exported, or entirely lowercase (e.g., http, url) if unexported. Http is valid and exported, but violates idiomatic Go style.
  • Underscores: An identifier starting with an underscore (e.g., _variable) is treated as lowercase and is unexported. The blank identifier (_) itself is never exported.
  • Non-Latin Characters: Go supports Unicode identifiers. A character like Ω (Greek Capital Letter Omega) is in the Unicode Lu category, so Ωmega is an exported identifier. ω (lowercase) makes ωmega unexported.
Master Go with Deep Grasping Methodology!Learn More