登录
首页 >  Golang >  Go问答

严格版本控制的 go.mod 文件

来源:stackoverflow

时间:2024-02-21 23:21:21 474浏览 收藏

IT行业相对于一般传统行业,发展更新速度更快,一旦停止了学习,很快就会被行业所淘汰。所以我们需要踏踏实实的不断学习,精进自己的技术,尤其是初学者。今天golang学习网给大家整理了《严格版本控制的 go.mod 文件》,聊聊,我们一起来看看吧!

问题内容

我在 go.mod 文件中的依赖项总是更新,但我不知道为什么。我有这样的 go.mod

module mymodule

go 1.14

require (
    github.com/golang/protobuf v1.3.5
    github.com/grpc-ecosystem/grpc-gateway v1.14.6
    github.com/jinzhu/gorm v1.9.15
    github.com/kelseyhightower/envconfig v1.4.0
    github.com/ruang-guru/rg-genproto v1.0.18
    gitlab.com/ruangguru/source/shared-lib/go v1.0.28
    google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884
    google.golang.org/grpc v1.29.1
)

当我运行 go get 时,它总是更改为这个。请参阅 github.com/golang/protobuf 从 1.3.5 到 1.4.1

require (
    github.com/golang/protobuf v1.4.1
    github.com/gomodule/redigo v2.0.0+incompatible
    github.com/grpc-ecosystem/grpc-gateway v1.14.6
    github.com/jinzhu/gorm v1.9.15
    github.com/kelseyhightower/envconfig v1.4.0
    github.com/ruang-guru/rg-genproto v1.0.18
    github.com/stretchr/testify v1.5.1
    gitlab.com/ruangguru/source/shared-lib/go v1.0.28
    google.golang.org/genproto v0.0.0-20200808173500-a06252235341
    google.golang.org/grpc v1.29.1
    google.golang.org/protobuf v1.25.0 // indirect
)

所以我的问题是,当我们运行 go get 时,如何在 go.mod 中设置特定版本而不更改它?如果这个问题非常基本,我很抱歉,因为我对这个 go.mod 还很陌生:(


解决方案


如果你的git包有tag版本,你可以使用这个命令:

go get -d -v github.com/golang/[email protected]
  • -d 表示“仅下载”,如果您想直接安装,请忽略此标志和此行下面的构建命令。
  • -v 的意思是“详细”。

今天关于《严格版本控制的 go.mod 文件》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>