Developing Our Own Packages

At some point, we are going to need to develop our own packages to organize our code and distribute it if needed. In Go, everything that begins with an uppercase letter is considered public and can be accessed from outside its package, whereas all other elements are considered private. The only exception to this Go rule is package names—it is a best practice to use lowercase package names, even though uppercase package names are allowed.

Compiling a Go package

Compiling a Go package can be done manually if it exists on the local machine. When a Go package is downloaded from the internet, it is compiled automatically. Additionally, if the downloaded package contains any errors, we’ll learn about them at the time of the download.

Let’s assume we want to manually compile a package saved in a file named post05.go file—we can use the following command:

Get hands-on with 1200+ tech skills courses.