Go1.12 概述
Go1.12
是目前最新的Go
版本,在Go1.11
发行之后的六个月到来,大多数的改变是工具链、运行时和包,总的来说,该版本依然保持了Go1
的兼容性承诺,希望大多数的程序还能和以前一样继续的编译和运行。
语言上的改变
语言规范上是没有改变的。
部分
- 竞争检测现在是支持在
linux/arm64
Go1.12
是最后一个支持FreeBSD 10.x
的版本,Go1.13
将开始支持FreeBSD 11.2+ or FreeBSD 12.0+
,FreeBSD 12.0+
要求设置一个COMPAT_FREEBSD11
的变量,这是默认设置的。- 在
linux/ppc64
上支持cgo
Windows
windows/arm
的部分支持go
在windows10 lot
的32位物联网arm
芯片上,比如树莓派3.
AIX
Go现在支持AIX 7.2及更高版本的POWER8体系结构(aix / ppc64)。尚不支持外部链接,cgo,pprof和竞赛检测器
Darwin
Go 1.12
是最后一个支持运行在macOS 10.10
系统之上的版本,Go1.13
将要求操作系统必须是macOS 10.11
以上。
工具
go tool vet 不再支持
go vet
命令将不在支持,关于这部分功能迁移到了analysis
工具中,更多详情查看包golang.org/x/tools/go/analysis,使用方式有所改变,不能再使用go tool vet
此命令,需要更改为go vet
命令,使用go vet
可以支持所以的版本。
-shadow
将不再可用,需要替换。
go get -u golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go vet -vettool=$(which shadow)
Tour将不在默认安装
Go Tour
不会包含再主要的包中,如果需要使用需要自行安装。
go get -u golang.org/x/tour
tour
Build cache 要求
如果设置了GOCACHE=off
将导致go
命令行写缓存失败。
二进制包
Go 1.12
是最后一个支持二进制包的版本.
Cgo
Go1.12
将C
语言的EGLDisplay
类型翻译为go
的uintptr
类型。更多信息请参考cgo 文档
核心库
TLS1.3
Go1.12
添加了对TLS 1.3
的支持,可以通过设置环境变量tls13=1GODEBUG
来启用,在Go1.13
版本中将默认开启。
bufio
如果在调用完Peek
方法之后调用UnreadRune and UnreadByte
将会返回一个错误。
bytes
func ReplaceAll(s, old, new []byte) []byte
新函数ReplaceAll
将返回一个字节切片的副本。s
是原字节,old
是匹配字节,new
是替换为新的字符。
package main
import (
"bytes"
"fmt"
)
func main() {
fmt.Printf("%s\n", bytes.ReplaceAll([]byte("oink oink oink"), []byte("oink"), []byte("moo")))
fmt.Printf("%s\n",bytes.ReplaceAll([]byte("this is a demo,place open the demo file"),[]byte("demo"),[]byte("test")))
}
//输出
moo moo moo
this is a test,place open the test file
crypto/rand
Reader.Read
如果超过60s还没有读取到熵,那么将会打印输出。
crypto/rc4
这个版本移除了其他版本的实现,只保留了Go
版本。
RC4
是一种流加密算法
crypto/tls
如果客户端发送的初始消息看起来不像TLS,则服务器将不再使用警报进行回复,当TLS记录头无效时,返回RecordHeaderError
.
type RecordHeaderError struct {
// Msg contains a human readable string that describes the error.
Msg string
// RecordHeader contains the five bytes of TLS record header that
// triggered the error.
RecordHeader [5]byte
// Conn provides the underlying net.Conn in the case that a client
// sent an initial handshake that didn't look like TLS.
// It is nil if there's already been a handshake or a TLS alert has
// been written to the connection.
Conn net.Conn // Go 1.12
}
database/sql
现在可以通过将*Rows
值传递给Row.Scan
方法来获取查询光标.
expvar
Delete
方法运行删除一个Map
类型的的key
.
func (v *Map) Delete(key string)
lib/time
当操作系统未提供时区数据时,将会使用配置的$GOROOT/lib/time/zoneinfo.zip
数据。