How to Use Struct Field Visibility (Exported vs Unexported)

Go struct fields starting with a capital letter are exported for external access, while lowercase fields remain private to the package.

In Go, struct fields starting with a capital letter are exported (public), while those starting with a lowercase letter are unexported (private). Exported fields are accessible from other packages, whereas unexported fields are only accessible within the same package.

type User struct {
    Name  string // Exported: accessible everywhere
    email string // Unexported: accessible only in this package
}