gpt4 book ai didi

go - 在 go 模块文件 (go.mod) 中使用 "go"版本指令有何含义

转载 作者:行者123 更新时间:2023-12-02 01:33:58 34 4
gpt4 key购买 nike

给定以下 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 推荐/必需的 Go 版本的指示符?这是一个我们应该在 Go 新版本发布时(每 6 个月)更新的指令吗?

最佳答案

应该按照最低要求的 Go 版本来考虑。如果您使用相同或更高版本的 Go 进行构建,那么一切都应该像 Go 1 compatibility promise 所 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

关于go - 在 go 模块文件 (go.mod) 中使用 "go"版本指令有何含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58204618/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com