Golang 如何更新Go mod 中的依赖

引言

在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)
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论抢沙发

请登录后发表评论