Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the implications of using the "go" version directive within a go module file (go.mod)

Tags:

go

go-modules

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)?

like image 431
mdwhatcott Avatar asked Oct 02 '19 15:10

mdwhatcott


People also ask

What is the use of go mod file?

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.

Which directive is used point to local go module?

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.

What is go mod version?

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.

Why are there 2 require in go mod?

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.


1 Answers

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

like image 54
TehSphinX Avatar answered Oct 18 '22 20:10

TehSphinX