Golang 如何更新Go mod 中的依赖

浏览:1180次阅读
没有评论

引言

在 golang 中对依赖的更新没有比较舒服的更新方式, 比如 php 中 composer 的更新依赖就很方便

以下内容可以来处理更新依赖

查看有更新的直接依赖项的方法

go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}{{end}}' -m all

该方法还有变种,比如查看更新的版本信息:

go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' -m all

那么如何更新

  • XArgs
go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}{{end}}' -m all | xargs go get -u
  • go get -u
go get -u $(go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}{{end}}' -m all)
正文完
 0
包子
版权声明:本站原创文章,由 包子 2023-02-28发表,共计509字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)