简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM