Exercise 09.01 – creating and using your first module
In this exercise, we will see how to create our first Go module with ease:
- Create a new directory called
bookutil
and navigate into it:mkdir bookutil cd bookutil
- Initialize a Go module named
bookutil
:go mod init bookutil
- Verify that
go.mod
is created within your project directory with the module path set asbookutil
.
Note
No go.sum
file is created after running go mod init
. It will be generated and updated as you interact with your module and add to its dependencies.
- Now, let’s create a Go package for the author information while focusing on functions related to book chapters by creating a directory named
author
within our module’s project directory. - Inside the
author
directory, create a file namedauthor.go
to define the package and functions.Here is the starting code for
author.go
:package author import "fmt" // Author represents an author of a book. type Author...