Exported and Unexported Code
Go has a very simple way to determine whether code is exported or unexported. Exported means that variables, types, functions, and so on are visible from outside of the package. Unexported means it is only visible from inside the package. If a function, type, variable, and so on starts with an uppercase letter, it is exportable; if it starts with a lowercase letter, it is unexportable. There are no access modifiers to be concerned with in Go
. If the function name is capitalized, then it is exported, and if it is lowercase, then it is unexported.
Note
It is good practice to only expose code that we want other packages to see. We should hide everything else that is not needed by external packages.
Let's look at the following code snippet:
package main import ("strings" "fmt" ) func main() { str := "found me" if strings.Contains(str, "found") { fmt.Println...