Go 1.12
最後更新
Go 1.12 發布於 2019-02-25,目前最新修補版為
go1.12.17,已停止支援,請升級到 go1.27.4。版本介紹
Go 1.12 是模組功能持續成熟的一版:
go.mod 的 go 指令開始代表模組使用的語言版本,模組下載也能安全地平行執行。對寫程式最直接的改變是 fmt 印映射時會依鍵排序,輸出從此可重現,測試比對更方便;crypto/tls 也開始可選擇啟用 TLS 1.3。工具
go.mod中的go 1.12這類指令代表該模組使用的語言版本。- 設定
GO111MODULE=on時,go get、go list等命令在模組目錄之外也能執行。 - 下載與解壓模組的
go命令可以安全地同時執行;replace指令會在查詢網路前優先使用。 go tool vet不再支援,請改用go vet。- 建置快取成為必要條件,無法再用
GOCACHE=off關閉。 - 這是最後一個支援二進位套件(binary-only package)的版本。
執行時與效能
- 當堆積中大部分物件仍存活時,清掃效能大幅提升,降低垃圾回收後的配置延遲。
- 執行時更積極地把記憶體還給作業系統;Linux 上改用
MADV_FREE。 - 計時器與截止時間(deadline)的程式碼更快,並能隨 CPU 數擴展,網路連線設定 deadline 時特別有感。
- 編譯器能內嵌更多函式,取得呼叫堆疊時務必使用
runtime.CallersFrames。
標準庫重點
fmt印出映射時依鍵排序,數字、字串依大小排列。crypto/tls支援 TLS 1.3,此版需以GODEBUG=tls13=1啟用,Go 1.13 起預設開啟。strings與bytes新增ReplaceAll,等同Replace(s, old, new, -1)。reflect新增Value.MapRange與MapIter,用迭代器走訪映射。os新增UserHomeDir;strings.Builder新增Cap方法。
fmt 依鍵排序印出映射
映射本身的走訪順序依然不固定,但
fmt 印出時會先把鍵排好。需要在自己的程式中依序處理映射時,仍要自行排序鍵。- package main
- import (
- "fmt"
- "strings"
- )
- func main() {
- scores := map[string]int{"carol": 70, "alice": 90, "bob": 80}
- fmt.Println(scores)
- flags := map[int]bool{3: true, 1: false, 2: true}
- fmt.Printf("%v\n", flags)
- fmt.Println(strings.ReplaceAll("a-b-c-d", "-", "/"))
- }
- map[alice:90 bob:80 carol:70]
- map[1:false 2:true 3:true]
- a/b/c/d
本版新增的棄用 API
以下 API 從 Go 1.12 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
| 套件 | 符號 | 官方說明 |
|---|---|---|
crypto/rc4 | Cipher.Reset | Reset can't guarantee that the key will be entirely removed from the process's memory. |
crypto/x509 | CertificateRequest.Attributes | Use Extensions and ExtraExtensions instead for parsing and generating the requestedExtensions attribute. |
go/importer | For | Use [ForCompiler], which populates a FileSet with the positions of objects created by the importer. |
net | Dialer.DualStack | Fast Fallback is enabled by default. To disable, set FallbackDelay to a negative value. |
net/http | ErrUnexpectedTrailer | ErrUnexpectedTrailer is no longer returned by anything in the net/http package. Callers should not compare errors against this variable. |
regexp | Regexp.Copy | In earlier releases, when using a [Regexp] in multiple goroutines, giving each goroutine its own copy helped to avoid lock contention. As of Go 1.12, using Copy is no longer necessary to avoid lock contention. Copy may still be appropriate if the reason for its use is to make two copies with different [Regexp.Longest] settings. |
修補版本
| 版本 | 發布日期 | 含安全修補 | 內容(官方原文) |
|---|---|---|---|
go1.12.1 | 2019-03-14 | 否 | includes fixes to cgo, the compiler, the go command, and the fmt, net/smtp, os, path/filepath, sync, and text/template packages. |
go1.12.2 | 2019-04-05 | 是 | includes security fixes to the runtime, as well as bug fixes to the compiler, the go command, and the doc, net, net/http/httputil, and os packages. |
go1.12.3 | 2019-04-08 | 否 | was accidentally released without its intended fix. It is identical to go1.12.2, except for its version number. The intended fix is in go1.12.4. |
go1.12.4 | 2019-04-11 | 否 | fixes an issue where using the prebuilt binary releases on older versions of GNU/Linux led to failures when linking programs that used cgo. Only Linux users who hit this issue need to update. |
go1.12.5 | 2019-05-06 | 否 | includes fixes to the compiler, the linker, the go command, the runtime, and the os package. |
go1.12.6 | 2019-06-11 | 否 | includes fixes to the compiler, the linker, the go command, and the crypto/x509, net/http, and os packages. |
go1.12.7 | 2019-07-08 | 否 | includes fixes to cgo, the compiler, and the linker. |
go1.12.8 | 2019-08-13 | 是 | includes security fixes to the net/http and net/url packages. |
go1.12.9 | 2019-08-15 | 否 | includes fixes to the linker, and the math/big and os packages. |
go1.12.10 | 2019-09-25 | 是 | includes security fixes to the net/http and net/textproto packages. |
go1.12.11 | 2019-10-17 | 是 | includes security fixes to the crypto/dsa package. |
go1.12.12 | 2019-10-17 | 否 | includes fixes to the go command, runtime, and the net and syscall packages. |
go1.12.13 | 2019-10-31 | 否 | fixes an issue on macOS 10.15 Catalina where the non-notarized installer and binaries were being rejected by Gatekeeper. Only macOS users who hit this issue need to update. |
go1.12.14 | 2019-12-04 | 否 | includes a fix to the runtime. |
go1.12.15 | 2020-01-09 | 否 | includes fixes to the runtime and the net/http package. |
go1.12.16 | 2020-01-28 | 是 | includes two security fixes to the crypto/x509 package. |
go1.12.17 | 2020-02-12 | 否 | includes a fix to the runtime. |
已知漏洞
在 Go 1.12 系列修補版中修正的漏洞共 7 個;仍影響最新修補版
go1.12.17 的漏洞共 192 個。本系列已修正
| 編號 | CVE | 摘要(官方原文) | 修正於 |
|---|---|---|---|
| GO-2022-0536 | CVE-2019-9512 | Reset flood in net/http and golang.org/x/net/http | go1.11.13、go1.12.8 |
| GO-2022-0535 | CVE-2020-0601 | Certificate validation bypass on Windows in crypto/x509 | go1.12.16、go1.13.7 |
| GO-2022-0229 | CVE-2020-7919 | Panic in certificate parsing in crypto/x509 and golang.org/x/crypto/cryptobyte | go1.12.16、go1.13.7 |
| GO-2022-0220 | CVE-2019-9634 | DLL injection on Windows in runtime and syscall | go1.11.10、go1.12.2 |
| GO-2022-0213 | CVE-2019-17596 | Panic on invalid DSA public keys in crypto/dsa | go1.12.11、go1.13.2 |
| GO-2022-0212 | CVE-2019-16276 | Request smuggling due to accepting invalid headers in net/http via net/textproto | go1.12.10、go1.13.1 |
| GO-2022-0211 | CVE-2019-14809 | Incorrect parsing validation in net/url | go1.11.13、go1.12.8 |
本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。