go.mod に記述されているライブラリのバージョンを上げる

github.com/shirou/gopsutil 使って書いたライブラリがあるのですが、ちょっとしかテストを書いてなかったのでChatGPTにテストを書かせてみようと思い立ってごにょごにょやってみた。
が、久しぶりにテストを流したら何やらWarningが表示されます。

$ make test
go test ./... -v
# github.com/shirou/gopsutil/v3/disk
iostat_darwin.c:28:2: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:143:1: note: 'IOMasterPort' has been explicitly marked deprecated here
# github.com/shirou/gopsutil/v3/host
smc_darwin.c:75:41: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:133:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here

ちょっと調べると以下のIssueが引っかかりました。

github.com

途中、 CGO_ENABLED="0" にしたら出なくなるよというのが書いてありますが、そうしたらメトリクス取れないじゃん…
最後まで読むと修正がMergeされてるようなのですが go mod tidy しても変わりはありません。

module github.com/gozuk16/gosi

go 1.16

require (
    github.com/inhies/go-bytesize v0.0.0-20201103132853-d0aed0d254f8
    github.com/shirou/gopsutil/v3 v3.21.4
)

今時点のgopsutilの最新はv3.23.5だからちょっと古いです。
そうか、go mod tidyしてもバージョンは上がらないのね。
調べたら以下のQ&Aが引っかかりました。

stackoverflow.com

go get で上げてから go mod tidy すればいいのね。Goのバージョンもだいぶ古いので先に上げとこう。

$ go version
go version go1.20.3 darwin/arm64

$ go mod tidy -go=1.20

$ go get -u
$ go mod tidy

結果、以下のようになりました。

module github.com/gozuk16/gosi

go 1.20

require (
    github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf
    github.com/shirou/gopsutil/v3 v3.23.5
)

require (
    github.com/go-ole/go-ole v1.2.6 // indirect
    github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
    github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
    github.com/shoenig/go-m1cpu v0.1.6 // indirect
    github.com/tklauser/go-sysconf v0.3.11 // indirect
    github.com/tklauser/numcpus v0.6.1 // indirect
    github.com/yusufpapurcu/wmi v1.2.3 // indirect
    golang.org/x/sys v0.9.0 // indirect
)

これでライブラリのバージョンが上がって、テストでWarning出なくなった!

ちなみにChatGPT(GPT-4)さんは普通にテストを書いてくれました。便利だなー。