在 go 模块文件 (go.mod) 中使用 "go" version 指令有什么影响

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

给定以下 go.mod 文件:

module foo

go 1.12

require (
    github.com/bar/baz v1.0.0
    github.com/rat/cat v1.0.0
)

go 1.12 表示什么?它会阻止针对任何其他版本的 Go 编译 foo 模块吗?或者它只是 foo 的 recommended/required Go 版本的一个指标?这是我们应该在新版本的 go 发布时(每 6 个月)更新的指令吗?

应该按照最低要求的 Go 版本来考虑。如果您使用相同或更高版本的 Go 构建,一切都应该像 Go 1 compatibility promise 所承诺的那样没问题。如果您使用较低版本构建,则构建失败时会出现错误消息:

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