Given the following go.mod file:
module foo
go 1.12
require (
github.com/bar/baz v1.0.0
github.com/rat/cat v1.0.0
)
What does the go 1.12
indicate? Does it prevent compiling the foo
module against any other version of Go? Or is it simply an indicator of the foo
's recommended/required Go version? Is this a directive that we should update whenever a new version of go is released (every 6 months)?
The go. mod file defines the module's module path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build. Each dependency requirement is written as a module path and a specific semantic version.
If you want to say, point to the local version of a dependency in Go rather than the one over the web, use the replace keyword.
Go uses an algorithm called minimal version selection (MVS) to select the versions to use. This is defined in a file named go. mod . The go. mod file specifies the versions of the packages that are used in the software program … and that's it.
Because in Go 1.17 the module graph has been changed to enable pruning and lazy loading. The second require block contains indirect dependencies. If a module specifies go 1.17 or higher, the module graph includes only the immediate dependencies of other go 1.17 modules, not their full transitive dependencies.
It should be considered along the lines of a minimum required Go Version. If you build with the same or a higher version of Go, all should be fine as promised by the Go 1 compatibility promise. If you build with a lower version there will be an error message if the build fails:
The go directive in a go.mod file now indicates the version of the language used by the files within that module. It will be set to the current release (go 1.12) if no existing version is present. If the go directive for a module specifies a version newer than the toolchain in use, the go command will attempt to build the packages regardless, and will note the mismatch only if that build fails. Go 1.12 Release Notes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With