Modules

A module is a collection of related Go packages that are versioned and released together. It is defined by a go.mod file at the root of the project.

The go.mod File

This file declares the module’s identity and its dependencies.

module github.com/username/myproject

go 1.21.0

require github.com/google/uuid v1.3.0
  • Module Path: The unique identifier for your project (often its URL on GitHub).
  • Go Version: The minimum version of Go required.
  • Dependencies: A list of other modules your project depends on.

Module vs. Package

  • Package: A single directory of code.
  • Module: A collection of packages (the entire repository).

Import Paths

An import path is the module path joined with the package’s subdirectory. For a module github.com/user/project with a utils/ folder, the import path would be github.com/user/project/utils.