Introduction
In the previous chapter, we looked at interfaces. We saw how we can use interfaces to describe the behavior of a type. We also discovered that we can pass different types to functions that accept an interface, as long as the type satisfies the interface's method sets. We also saw how we can achieve polymorphism using interfaces.
In this chapter, we will look at how Go organizes its code into packages. We will see how we can hide or expose different Go constructs such as structs, interfaces, functions, and more, using packages. Our programs have been rather small in the number lines of code and in complexity to a certain extent. Most of our programs have been contained in a single code file, often named main.go
, and inside a single package named main
. Later in this chapter, we will explore the significance of package main
, so do not be worried at this juncture if you do not understand it. This will not always be the case when you are working on a development team...