简体   繁体   English

在 go 模块文件 (go.mod) 中使用“go”版本指令的含义是什么

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

Given the following go.mod file:给定以下 go.mod 文件:

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? go 1.12表示什么? Does it prevent compiling the foo module against any other version of Go?它是否会阻止针对任何其他版本的 Go 编译foo模块? Or is it simply an indicator of the foo 's recommended/required Go version?或者它只是foo推荐/要求的 Go 版本的指标? Is this a directive that we should update whenever a new version of go is released (every 6 months)?每当发布新版本的 go 时(每 6 个月),我们是否应该更新此指令?

It should be considered along the lines of a minimum required Go Version.应该按照最低要求的 Go 版本来考虑。 If you build with the same or a higher version of Go, all should be fine as promised by the Go 1 compatibility promise .如果您使用相同或更高版本的 Go 构建,则一切都应该按照Go 1 兼容性 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. go.mod 文件中的 go 指令现在指示该模块中的文件使用的语言版本。 It will be set to the current release (go 1.12) if no existing version is present.如果不存在现有版本,它将设置为当前版本(转到 1.12)。 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 指令指定的版本比正在使用的工具链新,则 go 命令将尝试构建包,并且仅在构建失败时才会注意到不匹配。 Go 1.12 Release Notes Go 1.12 发行说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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