Go 1.11

最後更新


Go 1.11 發布於 2018-08-24,目前最新修補版為 go1.11.13,已停止支援,請升級到 go1.27.4。

版本介紹


Go 1.11 首次引入「模組(module)」:專案用一個 go.mod 檔記錄自己的路徑與依賴版本,不必再把程式碼放在 GOPATH 底下,建置也變得可重現。這是 Go 依賴管理的分水嶺,此版仍標示為實驗性質。同一版也加入實驗性的 WebAssembly 平台,Go 程式可以在瀏覽器中執行。

工具


  • 新增模組支援:在含 go.mod 的目錄(且位於 GOPATH 之外)自動啟用,也可用 GO111MODULE 環境變數控制;新增 go mod 子命令。
  • 新增實驗性 WebAssembly 平台(GOOS=js GOARCH=wasm),並提供 syscall/js 與 JavaScript 互動。
  • 最佳化過的執行檔有更準確的除錯資訊(DWARF),也可在 Delve 除錯器中呼叫 Go 函式。
  • go vet 遇到型別檢查錯誤時視為失敗;go run 可以指定套件目錄而不只是檔案。
  • runtime/trace 新增使用者註記 API,可在追蹤中標記任務(task)與區段(region)。
  • 保留 riscv 等架構名稱,*_riscv.go 之類的檔名會被視為平台限定檔案。

執行時與效能


  • 執行時改用稀疏堆積(sparse heap)配置,堆積大小不再有 512GiB 上限。
  • macOS 與 iOS 上改透過 libSystem.dylib 呼叫系統功能,提高與未來版本系統的相容性。
  • 編譯器能內嵌更多函式(包括呼叫 panic 的函式),並更積極地消除邊界檢查。
  • 編譯器會辨識「用 for range 逐一 delete 清空映射」與 append(s, make([]T, n)...) 的寫法並特別最佳化。

標準庫重點


  • 標準庫的改動都屬於小幅調整。
  • text/template 支援用 = 修改已宣告的樣板變數。
  • os 新增 UserCacheDir,取得使用者快取目錄的位置。
  • crypto/cipher 新增 NewGCMWithTagSize;crypto/rsa 的 PublicKey 新增 Size 方法。

樣板變數重新賦值


在 Go 1.11 之前,樣板變數宣告後就不能修改。現在可以在 range、if 之內用 = 改寫外層宣告的變數,常用來在迴圈中設定旗標。
  1. package main
  2. import (
  3. "os"
  4. "text/template"
  5. )
  6. const tpl = `{{$status := "pending" -}}
  7. {{range .}}{{if .Paid}}{{$status = "has paid order"}}{{end}}{{end -}}
  8. status: {{$status}}
  9. `
  10. type Order struct {
  11. ID int
  12. Paid bool
  13. }
  14. func main() {
  15. t := template.Must(template.New("t").Parse(tpl))
  16. t.Execute(os.Stdout, []Order{{1, false}, {2, true}})
  17. t.Execute(os.Stdout, []Order{{3, false}})
  18. }

  1. status: has paid order
  2. status: pending

本版新增的棄用 API


以下 API 從 Go 1.11 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
套件符號官方說明
archive/tarTypeRegAUse TypeReg instead.
net/httpCloseNotifierthe CloseNotifier interface predates Go's context package. New code should use [Request.Context] instead.
net/http/httptestResponseRecorder.HeaderMapHeaderMap exists for historical compatibility and should not be used. To access the headers returned by a handler, use the Response.Header map as returned by the Result method.

修補版本


版本發布日期含安全修補內容(官方原文)
go1.11.12018-10-01否includes fixes to the compiler, documentation, go command, runtime, and the crypto/x509, encoding/json, go/types, net, net/http, and reflect packages.
go1.11.22018-11-02否includes fixes to the compiler, linker, documentation, go command, and the database/sql and go/types packages.
go1.11.32018-12-12是includes three security fixes to "go get" and the crypto/x509 package.
go1.11.42018-12-14否includes fixes to cgo, the compiler, linker, runtime, documentation, go command, and the go/types and net/http packages. It includes a fix to a bug introduced in Go 1.11.3 that broke go get for import path patterns containing "...".
go1.11.52019-01-23是includes a security fix to the crypto/elliptic package.
go1.11.62019-03-14否includes fixes to cgo, the compiler, linker, runtime, go command, and the crypto/x509, encoding/json, net, and net/url packages.
go1.11.72019-04-05否includes fixes to the runtime and the net package.
go1.11.82019-04-08否was accidentally released without its intended fix. It is identical to go1.11.7, except for its version number. The intended fix is in go1.11.9.
go1.11.92019-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.11.102019-05-06是includes security fixes to the runtime, as well as bug fixes to the linker.
go1.11.112019-06-11否includes a fix to the crypto/x509 package.
go1.11.122019-07-08否includes fixes to the compiler and the linker.
go1.11.132019-08-13是includes security fixes to the net/http and net/url packages.

已知漏洞


在 Go 1.11 系列修補版中修正的漏洞共 7 個;仍影響最新修補版 go1.11.13 的漏洞共 196 個。

本系列已修正


編號CVE摘要(官方原文)修正於
GO-2022-0536CVE-2019-9512Reset flood in net/http and golang.org/x/net/httpgo1.11.13、go1.12.8
GO-2022-0220CVE-2019-9634DLL injection on Windows in runtime and syscallgo1.11.10、go1.12.2
GO-2022-0217CVE-2019-6486Denial of service affecting P-521 and P-384 curves in crypto/ellipticgo1.10.8、go1.11.5
GO-2022-0211CVE-2019-14809Incorrect parsing validation in net/urlgo1.11.13、go1.12.8
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

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

資料來源