LoginSignup
1
2

More than 1 year has passed since last update.

goでパッケージ更新

Last updated at Posted at 2022-11-14

概要

goで更新可能なパッケージを調べて、個別に更新する方法。

依存パッケージの確認

依存パッケージを全て出力

go list -f '{{join .Deps "\n"}}'

標準パッケージ以外の依存パッケージを出力

go list -f '{{join .Deps "\n"}}' | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'

更新可能なパッケージの確認

全パッケージ

indirect(間接利用)のものも出力される。

go list -m -u -mod=readonly all

indirectでないパッケージのみ

直接利用しているパッケージのみ出力。
出力結果の先頭にgo getを付けて出力することで、出力結果を使いやすくする。

go list -m -u -mod=readonly -f '{{if (and .Update (not .Indirect))}}go get {{.Path}}@{{.Update.Version}}{{end}}' all

以下のように、最新のバージョンが出力されるので、go getを実行し更新する。

go get github.com/aws/aws-sdk-go@v1.44.136
go get github.com/labstack/echo/v4@v4.9.1
go get gorm.io/gorm@v1.24.1
...

Refs

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2