Go – Package Scope

Package Scope in Go

Functions defined in files within a package are accessible from within the package.  Unless Exported, functions are not visible to code outside the package.

Within Go there is a similar concept to Private and Public methods.  The Scope in Go refers to this as Exported vs. Unexported.

Exporting Functions in Go

Functions can be exported out (made visible) to code outside the package and this is done via capitalization.

In the following example, the function Calculator is capitalized and therefore discoverable from code outside the package.

func Calculator() {


However a function defined as below will not be visible to code outside the package.

func calculator() {


Scope in Go is handled via capitalization.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Go: Setting Up

Golang – Variable Declaration, Assignment and Initialization