Home > Backend Development > Golang > Will 'go mod tidy' automatically upgrade the go version in go.mod?

Will 'go mod tidy' automatically upgrade the go version in go.mod?

王林
Release: 2024-02-06 09:05:04
forward
753 people have browsed it

“go mod tidy”会自动升级go.mod中的go版本吗?

Question content

Previously this project was using go 1.20 in go.mod. I have upgraded my go version to 1.21.0 on my local Linux machine.

When I ran go mod tidy for the project, it automatically upgraded go.mod to use go 1.21.0.

If this is expected behavior, is there a way to disable this behavior, aka. When running go mod tidy, won't the go version in go.mod be automatically updated? Because others may not have upgraded locally yet.


Correct Answer


The go mod tidy command (currently) does not change only based on the local toolchain version go.mod## The go directive in #. It is set up based on dependencies and does not require tracking patch versions.

If your dependencies require at least

go1.21, then your module requires go1.21, forcing go tools Update the go.mod directives in go.mod accordingly. There is no use having your module declare a version prior to go1.21 when building the module actually requires go1.21.

The above is the detailed content of Will 'go mod tidy' automatically upgrade the go version in go.mod?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template