Skip to content
Tech News
← Back to articles

Stop picking my Go version for me

read original get Go Programming Language T-Shirt → more articles
Why This Matters

This article highlights the importance of correctly specifying the Go version in go.mod files, emphasizing that it should represent the minimum supported version rather than the latest. Misusing this directive can lead to unnecessary constraints on dependent projects and confusion in build environments, impacting both developers and the broader Go ecosystem.

Key Takeaways

The go.mod file contains a mandatory go <version number> directive. Since Go 1.21, when a change was introduced to make this include a full patch number ( 1.21.0 instead of 1.21 ), a number of projects have started using this wrong, hurting everyone.

The version is the minimum version your project can be compiled with. It is not the version you use to compile your project, but the minimum version that anyone can use to compile your project.

This is viral: the version you put in your go.mod file will be the minimum version that any projects that depend on you can set.

This means when you put a version like 1.25.7 , you are deciding for everyone that imports you, transitively or directly, that they MUST be on Go 1.25.7+ to compile their project. Probably, your project doesn't actually depend on 1.25.7 and really just depends on 1.25.0 (if even that), and you should just put go 1.25.0 instead.

If you want to recommend users us a specific version when building your project (rather than the minimum that will be allowed to build) this can done with the toolchain directive instead.

Isn't it good to make sure users of my library are on the latest version?#

Its not your responsibility to ensure transitive importers of your library are on the latest version of Go. Don't make that decision for them.

But I want to use the latest versions in my builds!#

Tools like Github Actions actions/setup-go sometimes use the go directive of the go.mod file to determine the Go version to actually use.

This is wrong and shouldn't be done. If you do want to use it, you can use the toolchain directive instead (supported by actions/setup-go ), or other mechanisms to select the version.

... continue reading