Go 1.10

最後更新


Go 1.10 發布於 2018-02-16,目前最新修補版為 go1.10.8,已停止支援,請升級到 go1.27.4。

版本介紹


Go 1.10 大幅改善日常的建置與測試速度:go build 加入建置快取(build cache),依原始碼內容而非修改時間判斷是否需要重新編譯;go test 會快取通過的測試結果,並在執行測試前自動跑一輪 go vet。標準庫則新增了組字串的好幫手 strings.Builder。

語言變更


  • 沒有實質的語言變更,只釐清無型別常數位移與方法運算式(method expression)語法的邊角規則。

工具


  • go build 依檔案內容、建置旗標判斷套件是否過期,不再需要 -a 強制重建;新的建置快取讓 -i 不再必要。
  • go install 只安裝命令列上指定的套件,不再連依賴一起安裝。
  • go test 快取成功的測試結果,重跑時顯示 (cached);想強制重跑用 -count=1。
  • go test 執行前自動執行高可信度的 go vet 檢查,有問題就視同建置失敗;可用 -vet=off 關閉。
  • go test 新增 -failfast,遇到第一個失敗就停止後續測試。
  • cgo 可以直接在 Go 與 C 之間傳遞字串;編譯器旗標改用白名單,可能出現新的「invalid flag」錯誤。
  • gofmt 調整兩處格式細節:三索引切片的空白,以及單行的單一方法介面不再被拆成多行。

執行時與效能


  • LockOSThread 與 UnlockOSThread 改為巢狀計數:呼叫幾次鎖定就要呼叫幾次解鎖。
  • 堆疊追蹤不再出現編譯器自動產生的包裝函式(<autogenerated>)。
  • 垃圾回收降低對配置延遲的影響;GOMAXPROCS 不再有 1024 的上限。

標準庫重點


  • strings 新增 Builder,用 WriteString 等方法高效組合字串,最後以 String() 取得結果。
  • encoding/json 的 Decoder 新增 DisallowUnknownFields,遇到結構沒有的欄位就回傳錯誤。
  • math 新增 Round、RoundToEven、Erfinv 等函式。

strings.Builder


用 + 反覆串接字串時,每次都會產生新的字串;strings.Builder 在內部累積位元組,最後才轉成字串,迴圈組字串時更有效率。它實作 io.Writer,所以也能搭配 fmt.Fprintf。注意 Builder 用過之後不能複製。
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func main() {
  7. var b strings.Builder
  8. for i := 1; i <= 3; i++ {
  9. fmt.Fprintf(&b, "item-%d;", i)
  10. }
  11. b.WriteString("done")
  12. fmt.Println(b.String())
  13. fmt.Println(b.Len())
  14. }

  1. item-1;item-2;item-3;done
  2. 25

本版新增的棄用 API


以下 API 從 Go 1.10 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
套件符號官方說明
archive/tarHeader.XattrsUse PAXRecords instead.
archive/zipFileHeader.ModTimeUse [Modified] instead.
archive/zipFileHeader.ModifiedDateUse Modified instead.
archive/zipFileHeader.ModifiedTimeUse Modified instead.
archive/zipFileHeader.SetModTimeUse [Modified] instead.
encoding/csvErrTrailingCommaErrTrailingComma is no longer used.
encoding/csvReader.TrailingCommaTrailingComma is no longer used.

修補版本


版本發布日期含安全修補內容(官方原文)
go1.10.12018-03-28是includes security fixes to the go command, as well as bug fixes to the compiler, runtime, and the archive/zip, crypto/tls, crypto/x509, encoding/json, net, net/http, and net/http/pprof packages.
go1.10.22018-05-01否includes fixes to the compiler, linker, and go command.
go1.10.32018-06-05否includes fixes to the go command, and the crypto/tls, crypto/x509, and strings packages. In particular, it adds minimal support to the go command for the vgo transition.
go1.10.42018-08-24否includes fixes to the go command, linker, and the bytes, mime/multipart, net/http, and strings packages.
go1.10.52018-11-02否includes fixes to the go command, linker, runtime, and the database/sql package.
go1.10.62018-12-12是includes three security fixes to "go get" and the crypto/x509 package. It contains the same fixes as Go 1.11.3 and was released at the same time.
go1.10.72018-12-14否includes a fix to a bug introduced in Go 1.10.6 that broke go get for import path patterns containing "...".
go1.10.82019-01-23是includes a security fix to the crypto/elliptic package.

已知漏洞


在 Go 1.10 系列修補版中修正的漏洞共 5 個;仍影響最新修補版 go1.10.8 的漏洞共 199 個。

本系列已修正


編號CVE摘要(官方原文)修正於
GO-2022-0217CVE-2019-6486Denial of service affecting P-521 and P-384 curves in crypto/ellipticgo1.10.8、go1.11.5
GO-2022-0203CVE-2018-7187Remote command execution via "go get" command with "-insecure" option in cmd/gogo1.9.5、go1.10.1
GO-2022-0191CVE-2018-16875Denial of service in chain verification in crypto/x509go1.10.6、go1.11.3
GO-2022-0190CVE-2018-16874Directory traversal via "go get" command in cmd/gogo1.10.6、go1.11.3
GO-2022-0189CVE-2018-16873Remote command execution via "go get" with "-u" flag in cmd/gogo1.10.6、go1.11.3

本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。

資料來源