Chapter 14

Grouping Packages into Modules

IN THIS CHAPTER

Bullet Producing your own modules

Bullet Making sure your module is working

Bullet 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:

  1. Create the following directories on your computer:

    $HOME |__stringmod |__strings |__quotes

    This code creates a module named stringmod, with a subdirectory named strings. The idea is to group related functionalities into directories so as to logically group them together. The strings folder should contain functions related to strings. In this example, stringmod is a module and strings ...

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.