Go Modules


Configuration

Go modules were phased in using the $GO111MODULE environment variable. If set to on, the compiler required the presence of go.mod. The default is now on and no configuration is required.

To disable modules, try:

export GO111MODULE=off


Usage

go mod init git.example.com/user/repository

This will create a go.mod file, which will look like:

module git.example.com/user/repository

go 1.19

require (
        github.com/mattn/go-isatty v0.0.16
)

require (
        golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
)

Dep

Before the introduction of modules, the preferred method for managing dependencies was Dep. This involves a pair of files (Gopkg.toml and Gopkg.lock) as well as the vendor directory.

To migrate from Dep to modules, try:

go mod init git.example.com/user/repository
go mod tidy
go build .
rm --recursive --force vendor/ Gopkg.lock Gopkg.toml


CategoryRicottone

Go/Modules (last edited 2022-09-30 15:56:56 by DominicRicottone)