Modules | Go
Go Modules#
Go 1.11 introduced Modules, enabling an alternative workflow. This new approach will gradually become the default mode, deprecating the use of GOPATH.
Modules aim to solve problems related to dependency management, version selection and reproducible builds; they also enable users to run Go code outside of GOPATH.
Using Modules is pretty straightforward. Select any directory outside GOPATH as the root of your project, and create a new module with the go mod init command.
A go.mod file will be generated, containing the module path, a Go version, and its dependency requirements, which are the other modules needed for a successful build.
If no <modulepath> is specified, go mod init will try to guess the module path from the directory structure, but it can also be overrided, by supplying an argument.
A go.mod file could look like this:
The built-in documentation provides an overview of all available go mod commands.