In Go, the first letter of a name controls its visibility.
There are no public or private keywords.
↳ 1) Exported — starts with an uppercase letter
Accessible from other packages.
type User struct {
Name string // exported
Email string // exported
}↳ 2) Unexported — starts with a lowercase letter
Only accessible within the same package.
type User struct {
Name string // exported
password string // unexported
}Methods follow the same rule:
func (u User) GetName() string { ... } // exported
func (u User) validate() bool { ... } // unexportedWhen you import a struct from another package, you can only access exported fields and methods.
This is how Go controls visibility across packages.
Since all exercises in this guide are single-file package main programs, both exported and unexported fields work within the same file. The distinction matters when code spans multiple packages.
There are some exported and unexported fields in main.go file.
But they are incomplete.
Open main.go file and complete the code lines.
Then validate your code by running:
go run topic.go 33 validate✅ If everything is ok, you should see:
OK!
Now you know how exported fields work in Go.
Continue to the next topic 👇
