Go 1.14
最後更新
Go 1.14 發布於 2020-02-25,目前最新修補版為
go1.14.15,已停止支援,請升級到 go1.27.4。版本介紹
Go 1.14 宣布模組(module)已可用於正式環境,鼓勵所有專案從
GOPATH 遷移到模組。執行時方面有兩個大進步:goroutine 可以被非同步搶占(asynchronous preemption),沒有函式呼叫的緊密迴圈不再卡住排程器或延誤垃圾回收;defer 的開銷則降到幾乎和直接呼叫一樣,效能敏感的程式碼也能放心使用。語言變更
- 介面嵌入允許方法重疊:嵌入的多個介面中有同名、同簽名的方法時不再報錯,解決菱形嵌入的問題;直接宣告的方法仍不可重複。
工具
- 模組可用於正式環境;
go.mod宣告go 1.14以上且有vendor目錄時,預設使用-mod=vendor。 - 新增
-mod=mod(從模組快取載入)與-modcacherw(讓模組快取目錄可寫入)旗標。 go.mod唯讀且沒有vendor目錄時,預設採用-mod=readonly。- 編譯器新增
-d=checkptr,在執行時檢查unsafe.Pointer的使用是否符合規則,-race、-msan時預設啟用(Windows 除外)。 - 編譯器可用
-json輸出內嵌、逃逸分析等最佳化決策的紀錄。 - 新增實驗性的 64 位元 RISC-V Linux 平台;移除 Native Client(NaCl)支援。
執行時與效能
- 大多數
defer幾乎零額外開銷。 - goroutine 可被非同步搶占;副作用是 Unix 上的程式會收到更多訊號,慢速系統呼叫可能回傳
EINTR。 - 頁面配置器在高
GOMAXPROCS下的鎖競爭大幅減少。 time.After、time.Tick、net.Conn.SetDeadline使用的內部計時器更有效率。
標準庫重點
- 新增
hash/maphash,提供給雜湊表使用的位元組序列雜湊函式(非加密用途,每個行程結果不同)。 testing新增T.Cleanup、B.Cleanup,註冊在測試結束後執行的清理函式。crypto/tls移除 SSLv3 支援。math新增FMA,計算x*y+z且中間不捨入;log新增Lmsgprefix旗標。
重疊的介面嵌入
ReadCloser 與 WriteCloser 都有 Close() error。Go 1.14 之前把兩者嵌入同一個介面會出現「duplicate method」錯誤,現在因為簽名相同而被允許,Close 只算一個方法。- package main
- import (
- "fmt"
- "strings"
- )
- type ReadCloser interface {
- Read() string
- Close() error
- }
- type WriteCloser interface {
- Write(s string)
- Close() error
- }
- type ReadWriteCloser interface {
- ReadCloser
- WriteCloser
- }
- type memFile struct {
- sb strings.Builder
- closed bool
- }
- func (f *memFile) Read() string { return f.sb.String() }
- func (f *memFile) Write(s string) { f.sb.WriteString(s) }
- func (f *memFile) Close() error {
- f.closed = true
- return nil
- }
- func main() {
- var rwc ReadWriteCloser = &memFile{}
- rwc.Write("hello")
- fmt.Println(rwc.Read())
- rwc.Close()
- fmt.Println(rwc.(*memFile).closed)
- }
- hello
- true
本版新增的棄用 API
以下 API 從 Go 1.14 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
| 套件 | 符號 | 官方說明 |
|---|---|---|
crypto/tls | Config.BuildNameToCertificate | NameToCertificate only allows associating a single certificate with a given name. Leave that field nil to let the library select the first compatible chain from Certificates. |
crypto/tls | Config.NameToCertificate | NameToCertificate only allows associating a single certificate with a given name. Leave this field nil to let the library select the first compatible chain from Certificates. |
net/http | Transport.DialTLS | Use DialTLSContext instead, which allows the transport to cancel dials as soon as they are no longer needed. If both are set, DialTLSContext takes priority. |
修補版本
| 版本 | 發布日期 | 含安全修補 | 內容(官方原文) |
|---|---|---|---|
go1.14.1 | 2020-03-19 | 否 | includes fixes to the go command, tools, and the runtime. |
go1.14.2 | 2020-04-08 | 否 | includes fixes to cgo, the go command, the runtime, and the os/exec and testing packages. |
go1.14.3 | 2020-05-14 | 否 | includes fixes to cgo, the compiler, the runtime, and the go/doc and math/big packages. |
go1.14.4 | 2020-06-01 | 否 | includes fixes to the go doc command, the runtime, and the encoding/json and os packages. |
go1.14.5 | 2020-07-14 | 是 | includes security fixes to the crypto/x509 and net/http packages. |
go1.14.6 | 2020-07-16 | 否 | includes fixes to the go command, the compiler, the linker, vet, and the database/sql, encoding/json, net/http, reflect, and testing packages. |
go1.14.7 | 2020-08-06 | 是 | includes security fixes to the encoding/binary package. |
go1.14.8 | 2020-09-01 | 是 | includes security fixes to the net/http/cgi and net/http/fcgi packages. |
go1.14.9 | 2020-09-09 | 否 | includes fixes to the compiler, linker, runtime, documentation, and the net/http and testing packages. |
go1.14.10 | 2020-10-14 | 否 | includes fixes to the compiler, runtime, and the plugin and testing packages. |
go1.14.11 | 2020-11-05 | 否 | includes fixes to the runtime, and the net/http and time packages. |
go1.14.12 | 2020-11-12 | 是 | includes security fixes to the go command and the math/big package. |
go1.14.13 | 2020-12-03 | 否 | includes fixes to the compiler, runtime, and the go command. |
go1.14.14 | 2021-01-19 | 是 | includes security fixes to the go command and the crypto/elliptic package. |
go1.14.15 | 2021-02-04 | 否 | includes fixes to the compiler, runtime, the go command, and the net/http package. |
已知漏洞
在 Go 1.14 系列修補版中修正的漏洞共 9 個;仍影響最新修補版
go1.14.15 的漏洞共 184 個。本系列已修正
| 編號 | CVE | 摘要(官方原文) | 修正於 |
|---|---|---|---|
| GO-2022-0476 | CVE-2020-28367 | Arbitrary code execution via the go command with cgo in cmd/go | go1.14.12、go1.15.5 |
| GO-2022-0475 | CVE-2020-28366 | Arbitrary code execution in go command with cgo in cmd/go and cmd/cgo | go1.14.12、go1.15.5 |
| GO-2021-0235 | CVE-2021-3114 | Incorrect operations on the P-224 curve in crypto/elliptic | go1.14.14、go1.15.7 |
| GO-2021-0226 | CVE-2020-24553 | Cross-site scripting in net/http/cgi and net/http/fcgi | go1.14.8、go1.15.1 |
| GO-2021-0224 | CVE-2020-15586 | Data race and crash in net/http | go1.13.13、go1.14.5 |
| GO-2021-0223 | CVE-2020-14039 | Certificate verification error on Windows in crypto/x509 | go1.13.13、go1.14.5 |
| GO-2021-0142 | CVE-2020-16845 | Unbounded read from invalid inputs in encoding/binary | go1.13.15、go1.14.7 |
| GO-2021-0069 | CVE-2020-28362 | Panic during division of very large numbers in math/big | go1.14.12、go1.15.5 |
| GO-2021-0068 | CVE-2021-3115 | Arbitrary code injection via the go command with cgo on Windows in cmd/go | go1.14.14、go1.15.7 |
本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。