Go uses a naming convention to indicate the visibility and accessibility of variables, functions, and types.
If a variable, function, or type name starts with an uppercase
letter, it is considered exported (public) and can be accessed from other packages. For example, if you have a variable named MyVariable
or a function named MyFunction
, they are considered public and can be accessed from other packages
package mypackage
// Exported variable
var MyVariable int
// Exported function
func MyFunction() {
// ...
}
If a variable, function, or type name starts with a lowercase
letter, it is considered unexported (private) and can only be accessed within the same package. For example, if you have a variable named myVariable
or a function named myFunction
, they are considered private and cannot be accessed from other packages
package mypackage
// Unexported variable
var myVariable int
// Unexported function
func myFunction() {
// ...
}
So, in summary, Go doesn't have explicit access modifiers like public
or private
, but it relies on the naming convention
to determine the visibility and accessibility of entities within and outside a package