Go Packages and Functions
The focus of this chapter is on Go packages, which are the Go way of organizing, delivering, and using code. Packages are used to organize related functionality in your code. As the package author, you design the package, including the public API consisting of exported constants, variables, types, and functions. Go also supports modules, which contain one or more packages. Modules are versioned following SemVer, allowing the module author to release updates and even breaking changes using a major.minor.patch
versioning scheme. This chapter will also explain the operation of defer
, which is typically used for cleaning up and releasing resources.
Regarding the visibility of package elements, Go follows a simple rule which states that functions, variables, data types, structure fields, and so forth that begin with an uppercase letter are public, whereas functions, variables, types, and so forth that begin with a lowercase letter are private. This is the...