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 |__quotesThis 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. Thestringsfolder should contain functions related to strings. In this example,stringmodis a module andstrings ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access