liveBook · Manning

Public visibility

As explained in Learn Go with Pocket-Sized Projects

Visibility is the rule determining whether a Go identifier can be referenced from outside its package, based on its initial capitalization.

Public visibility determines whether a Go identifier can be referenced outside its package: names beginning with a capital letter are exposed. section 2.1.1

Apply the rule consistently when sharing identifiers:

  • Use an uppercase initial for functions or variables that another package must access, such as fmt.Println. section 2.1.1
  • Expose struct fields required by templates; changing a field from exposed to unexposed prevents the template from printing it. section 11.2.2

Calling an exposed function

package main import "fmt" func main() { fmt.Println("Hello world") } The capitalized Println identifier is accessible through the imported fmt package, producing Hello world when the program runs. section 2.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines capitalization and demonstrates practical access failures, without detailing broader scope rules.
Examples
Uses fmt.Println in a runnable program and Name or WeeklyFrequency in an HTML template.
What you can do after
Apply it by capitalizing identifiers that other packages or templates must access.
How it connects
Connects package imports, exported functions, struct fields, and Go templates.

Also explained in

Compare how 8 books explain public visibility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.