前言
Go官方团队在2022.12.08发布了Go 1.20 rc1(release candidate)版本,Go 1.20的正式release版本预计会在2023年2月份发布。
让我们先睹为快,看看Go 1.20给我们带来了哪些变化。
安装方法:
$ go install golang.org/dl/go1.20rc1@latest
$ go1.20rc1 download
这是Go 1.20版本更新内容详解的第2篇,欢迎大家关注公众号,及时获取本系列最新更新。
第1篇主要涉及Go 1.20在语言、可移植性方面的优化,原文链接:Go 1.20版本升级内容第1篇。
Go 1.20发布清单
和Go 1.19相比,改动内容适中,主要涉及语言(Language)、可移植性(Ports)、工具链(Go Tools)、运行时(Runtime)、编译器(Compiler)、汇编器(Assembler)、链接器(Linker)和核心库(Core library)等方面的优化。
本文重点介绍Go 1.20在Go工具链方面的优化。
Go command
$GOROOT/pkg
路径不再存储标准库源代码编译后生成的文件,包括以下几点:
go install
不再往$GOROOT/pkg
目录写文件。go build
不再检查$GOROOT/pkg
下的文件。- Go发布包不再带有这些编译文件。
以macOS环境来演示:在Go 1.16版本里,$GOROOT/pkg
目录下的内容如下:
$ go version
go version go1.16.5 darwin/amd64
$ go env GOROOT
/usr/local/opt/go/libexec
$ ls /usr/local/opt/go/libexec/pkg
darwin_amd64 darwin_amd64_race include tool
但是在Go 1.20rc1版本里,$GOROOT/pkg
目录下的内容如下:
$ go1.20rc1 version
go version go1.20rc1 darwin/amd64
$ go1.20rc1 env GOROOT
/Users/xxx/sdk/go1.20rc1
$ ls /Users/xxx/sdk/go1.20rc1/pkg
include tool
少了darwin_amd64
和darwin_amd64_race
这2个文件夹:
$ ls /usr/local/opt/go/libexec/pkg/darwin_amd64
archive database go io net.a runtime testing.a
bufio.a debug hash io.a os runtime.a text
bytes.a embed.a hash.a log os.a sort.a time
cmd encoding html log.a path strconv.a time.a
compress encoding.a html.a math path.a strings.a unicode
container errors.a image math.a plugin.a sync unicode.a
context.a expvar.a image.a mime reflect.a sync.a vendor
crypto flag.a index mim