liveBook · Manning

Go module

As explained in Go in Action, Second Edition

A Go module is a versioned collection of Go packages described by a go.mod file and managed as a unit for dependency resolution and builds.

A Go module groups one or more packages into a named project that Go can build and manage as a unit. Its root directory contains go.mod, which identifies the module and records information needed to resolve dependencies. A module can be a reusable library or an installable application. section 2.3.2 section 11.0

Start a module

Create a wordcount directory, enter it, and run `go mod init gobook/wordcount`. The resulting go.mod begins with `module gobook/wordcount` and `go 1.25`. The go command consults that file when building code in the module directory and its subdirectories. This new project has no external dependencies yet. section 2.3.1 section 2.3.2

As the project grows, go.mod can list required modules and their versions, including indirect dependencies. `go get` can request a latest or specific version; `go.sum` holds cryptographic information for dependency verification. Modules use semantic versions, so dependencies can be managed as projects change. section 11.1 section 11.4

module github.com/YOUR_USERNAME/go-news/api #1

go 1.25 #2

require ( #3
    github.com/YOUR_USERNAME/go-news/domain v0.0.1
    github.com/gorilla/mux v1.8.0
)

require (
    github.com/other/transitive v0.5.2 // indirect #4
)

A service module’s go.mod shows its module path, Go version, direct requirements, and an indirect requirement. section 11.1

Module boundaries become useful when components need to evolve separately. An RSS reader can split its shared domain model, storage, REST API, and background worker into four modules. During local development, a workspace coordinates changes across modules through go.work without requiring each change to be published as a new version. section 11.0 section 11.4

How Go in Action, Second Edition covers it

How deep it goes
Works through initialization, go.mod entries, dependency commands, and multimodule organization without detailing the dependency-resolution algorithm.
Examples
Uses a word-count project and a four-module RSS reader with domain, storage, API, and worker components.
What it assumes
Introduces module setup from an empty directory but expects basic Git commands for the hosted multimodule project.
What you can do after
Build it from scratch: initialize a module, inspect go.mod, and plan separate modules for components that should evolve independently.
How it connects
Connects modules to packages, semantic versioning, go.sum, workspaces, and domain-driven design.

Also explained in

Compare how 4 books explain go module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.