Chapter 14
Grouping Packages into Modules
IN THIS CHAPTER
Producing your own modules
Making sure your module is working
Getting your module onto GitHub
In Go, a module is a directory of packages, with a file named go.mod
at its root. The go.mod
file defines the module's path, as well as the dependency requirements (that is, the packages and modules that are needed by this module in order for it to work correctly).
The best way to understand what is a module is to actually create one. In this chapter, I explain how to convert a group of packages into a module so that you can publish it and make it available for use by other Go developers.
Creating a Module
When you create a module, you can publish it and make it available for use by other Go developers. To create a module, follow these steps:
- Create the following directories on your computer:
$HOME |__stringmod |__strings |__quotes
This code creates a module named
stringmod
, with a subdirectory namedstrings
. The idea is to group related functionalities into directories so as to logically group them together. Thestrings
folder should contain functions related to strings. In this example,stringmod
is a module andstrings ...
Get Go Programming Language For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.