liveBook · Manning

Module path

As explained in Go in Action, Second Edition

A module path is the identifier that names a Go module and distinguishes it when resolving versions and imports.

A module path uniquely identifies a Go module and provides the import path prefix for its packages. For a module hosted on GitHub or GitLab, match the path to the repository location so the Go command can fetch it. In a repository containing multiple modules, include each module’s subdirectory in its path. section 11.1

cd domain
go mod init github.com/YOUR_USERNAME/go-news/domain

Initialize the domain module with a path that includes its repository and subdirectory. The command creates a go.mod file declaring that path. section 11.1

Dependencies are recorded in go.mod with a module path and version. Use go get with a package path to add a dependency, or add an import and run go mod tidy. Major versions use a path suffix such as /v2 or /v3. section 11.1

cd storage
go mod init github.com/YOUR_USERNAME/go-news/storage
go get github.com/YOUR_USERNAME/go-news/domain@v0.0.1
go get go.etcd.io/bbolt@v1.3.11

The storage module has its own path and adds the domain module at a specific version. section 11.2

In a multimodule repository, prefix a version tag with the module’s subdirectory. For example, domain/v0.0.1 identifies the domain module’s release, rather than a release of the repository as a whole. section 11.2

cd domain
git add .
git commit -m "Initial domain module with core entities and interfaces"
git tag domain/v0.0.1
git push origin domain/v0.0.1

Commit, tag, and push the domain module’s initial version using its subdirectory prefix. section 11.2

How Go in Action, Second Edition covers it

How deep it goes
Defines module paths and demonstrates initialization, dependency selection, major-version suffixes, and repository subdirectory tags.
Examples
Uses domain and storage modules in a news project, including a domain/v0.0.1 tag and a versioned dependency.
What you can do after
Apply it via go mod init and go get to name modules and select a dependency version.
How it connects
Connects module paths to package imports, go.mod, semantic versioning, and multimodule repositories.

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.