简体   繁体   English

如何在运行 go mod 下载时强制使用特定的 package 版本?

[英]How can I force to use specific package version while running go mod download?

go.mod file go.mod 文件

go 1.13

require (
  ...
  gorm.io/gorm v1.20.5
) 

When I run go mod download then my go.mod file becomes当我运行go mod download时,我的 go.mod 文件变为

go 1.13

require (
  ...
  gorm.io/gorm v1.20.7
) 

How can I stop this upgrade while running go mod download ?如何在运行go mod download时停止此升级?

You can try -mod=readonly when running code您可以在运行代码时尝试-mod=readonly

reference is here https://golang.org/ref/mod#go-mod-file-updates参考在这里https://golang.org/ref/mod#go-mod-file-updates

The -mod=readonly flag prevents commands from automatically updating go.mod. -mod=readonly 标志防止命令自动更新 go.mod。 However, if a command needs to perform an action that would update to go.mod, it will report an error.但是,如果命令需要执行将更新为 go.mod 的操作,它将报告错误。 For example, if go build is asked to build a package not provided by any module in the build list, go build will report an error instead of looking up the module and updating requirements in go.mod. For example, if go build is asked to build a package not provided by any module in the build list, go build will report an error instead of looking up the module and updating requirements in go.mod.

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

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