Appendix A. Modules and packages
We'll write, compile, and run an executable program that prints the title of this book to the console. This tiny program introduces us to modules, packages, exporting and importing, and idiomatic naming conventions. Let's review our project's packages and directory structure.
A.1 Packages
In Go, we write our code inside packages. A package is a set of Go source code files in the same directory. Every source file in a package directory must declare the same package.
NOTE
Source code files in the same package are compiled together.
There are two kinds of packages:
- Packages named main are for building executables and cannot be imported.
- Packages named anything but main can be imported from other packages.
NOTE
Only packages named main can be built into executables because the Go toolchain uses the main function in the main package as the program's entry point.
As illustrated by Figure A.1, our example tiny program has two packages:
- Package main is the entry point to our executable program.
- Package book is an importable package. Its Title function returns this book's title.
The main package will import the book package and call Title to print this book's title.
Figure A.1 The main package imports the book package to use its functionality. The main package's main function calls the book package's Title function.

TIP
Package names are concise nouns, like book. They are lowercase and lack underscores. They convey what the package offers, not what it contains.