⇤ ← Revision 1 as of 2022-09-30 15:55:40
Size: 1088
Comment:
|
Size: 1121
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 11: | Line 11: |
Go modules were phased in using the `$GO111MODULE` environment variable. If set to `on`, the compiler required the presence of `go.mod`. | 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. |
Line 13: | Line 13: |
The default is now `on`. To disable modules, try: | To disable modules, try: |
Go Modules
Contents
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