LoginSignup
0
0

Go 1.20で気をつけたいアップデート内容

Last updated at Posted at 2023-02-19

はじめに

2月1日に公開されたGo1.20
こちらのアップデート内容で、動作などに影響を及ぼす、注意すべき内容を書いていきます。

注意したいアップデート

1. Darwin and iOS

Go 1.20 is the last release that will run on macOS 10.13 High Sierra or 10.14 Mojave. Go 1.21 will require macOS 10.15 Catalina or later.

MacのOSはCatalina以降でないと動作しないよという内容です。
Catalinaは2019年くらいに公開されたOSなので、アップデートしてない人はほぼいないと思いますが、一応注意したいところ。

2. Go command

The directory $GOROOT/pkg no longer stores pre-compiled package archives for the standard library

GOROOT/pkg ディレクトリには、標準ライブラリのプリコンパイルされたパッケージアーカイブが保存されなくなるとのこと。必要に応じてビルドされるとか。ということは自分でライブラリをコンパイルする機会が増加するかもしれません。ライブラリのアップグレードやバージョンの切り替えに手間がかかるかも。

The implementation of go test -json has been improved to make it more robust. Programs that run go test -json do not need any updates. Programs that invoke go tool test2json directly should now run the test binary with -v=test2json (for example, go test -v=test2json or ./pkg.test -test.v=test2json) instead of plain -v.

test2jsonを直接呼び出すプログラムは-vの代わりに-v=test2json を指定して (たとえば go test -v=test2json や ./pkg.test -test.v=test2json) テストバイナリを実行しなければならなくなるとのこと。
test2jsonはテストコマンドの結果をjsonにしてくれるオプションのよう。https://pkg.go.dev/cmd/test2json
今まで -v だけで呼び出していた人は気をつけたいところ。

When the main module is located within GOPATH/src, go install no longer installs libraries for non-main packages to GOPATH/pkg, and go list no longer reports a Target field for such packages.

非メインパッケージのコンパイル済みアーカイブがGOPATH/pkgに保存されなくなったので依存関係に問題が発生するかも。おとなしくモジュールモードにしておけってことですね。1.13からデフォルトがモジュールモードなので、あまり気にしなくてもいいかもしれませんが。
ちなみに go env GOMOD でモジュールモードかどうかはわかります。

3. rand.Seed()が再現性のない値を返すようになった

rand.Seed()にお世話になっている人は多いと思います。今までrand.Seedは一度生成した乱数の値は固定だったのですが、今回からseedの値によらず完全に生成値はランダムになりました。
そのため、再現性のある乱数生成を要求する場合は rand.New(rand.NewSource(seed))を使用しなければなりません。

The math/rand package now automatically seeds the global random number generator (used by top-level functions like Float64 and Int) with a random value, and the top-level Seed function has been deprecated. Programs that need a reproducible sequence of random numbers should prefer to allocate their own random source, using rand.New(rand.NewSource(seed)).

参考文献

公式サイト :
https://go.dev/doc/go1.20

0
0
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
0
0