liveBook · Manning

Go.mod file

As explained in Go in Practice, Second Edition

A go.mod file declares a Go module's module path, target Go version, and required dependencies.

A go.mod file holds a Go module’s identity and configuration: its module path, target Go version, and any declared third-party dependencies. Create it at the top level of a new project before adding application code. section 1.2.4 section 1.5

Initialize a project

From the project directory, run `go mod init hellogo`. This creates go.mod; you can then add main.go in the same directory. If you plan to share the project, use a unique module path, commonly a repository URL path such as `github.com/[USERNAME]/[REPO]`, instead of `hellogo`. section 1.5

Third-party dependencies added with `go get` appear in go.mod. After manually changing the target version or removing dependencies, run `go mod tidy` to clean up the dependency tree and file. section 1.2.4

How Go in Practice, Second Edition covers it

How deep it goes
Explains how to create and maintain the file, but does not show its literal syntax or dependency entries.
Examples
Uses `go mod init hellogo` before creating a small HTTP server, and offers a repository URL path as a shareable alternative.
What it assumes
Assumes access to a project directory and Go commands; introduces module initialization without requiring an existing module.
What you can do after
Operate/configure it with `go mod init`, `go get`, and `go mod tidy` to initialize a project and maintain dependency declarations.
How it connects
Connects Go modules to module paths, third-party dependencies, and Go’s command-line toolchain.

Also explained in

Compare how 3 books explain go.mod file →

Related concepts

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