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 之內用 = 改寫外層宣告的變數,常用來在迴圈中設定旗標。- package main
- import (
- "os"
- "text/template"
- )
- const tpl = `{{$status := "pending" -}}
- {{range .}}{{if .Paid}}{{$status = "has paid order"}}{{end}}{{end -}}
- status: {{$status}}
- `
- type Order struct {
- ID int
- Paid bool
- }
- func main() {
- t := template.Must(template.New("t").Parse(tpl))
- t.Execute(os.Stdout, []Order{{1, false}, {2, true}})
- t.Execute(os.Stdout, []Order{{3, false}})
- }
- status: has paid order
- status: pending
本版新增的棄用 API
以下 API 從 Go 1.11 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
| 套件 | 符號 | 官方說明 |
|---|---|---|
archive/tar | TypeRegA | Use TypeReg instead. |
net/http | CloseNotifier | the CloseNotifier interface predates Go's context package. New code should use [Request.Context] instead. |
net/http/httptest | ResponseRecorder.HeaderMap | HeaderMap 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.1 | 2018-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.2 | 2018-11-02 | 否 | includes fixes to the compiler, linker, documentation, go command, and the database/sql and go/types packages. |
go1.11.3 | 2018-12-12 | 是 | includes three security fixes to "go get" and the crypto/x509 package. |
go1.11.4 | 2018-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.5 | 2019-01-23 | 是 | includes a security fix to the crypto/elliptic package. |
go1.11.6 | 2019-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.7 | 2019-04-05 | 否 | includes fixes to the runtime and the net package. |
go1.11.8 | 2019-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.9 | 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.11.10 | 2019-05-06 | 是 | includes security fixes to the runtime, as well as bug fixes to the linker. |
go1.11.11 | 2019-06-11 | 否 | includes a fix to the crypto/x509 package. |
go1.11.12 | 2019-07-08 | 否 | includes fixes to the compiler and the linker. |
go1.11.13 | 2019-08-13 | 是 | includes security fixes to the net/http and net/url packages. |
已知漏洞
在 Go 1.11 系列修補版中修正的漏洞共 7 個;仍影響最新修補版
go1.11.13 的漏洞共 196 個。本系列已修正
| 編號 | 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-0220 | CVE-2019-9634 | DLL injection on Windows in runtime and syscall | go1.11.10、go1.12.2 |
| GO-2022-0217 | CVE-2019-6486 | Denial of service affecting P-521 and P-384 curves in crypto/elliptic | go1.10.8、go1.11.5 |
| GO-2022-0211 | CVE-2019-14809 | Incorrect parsing validation in net/url | go1.11.13、go1.12.8 |
| GO-2022-0191 | CVE-2018-16875 | Denial of service in chain verification in crypto/x509 | go1.10.6、go1.11.3 |
| GO-2022-0190 | CVE-2018-16874 | Directory traversal via "go get" command in cmd/go | go1.10.6、go1.11.3 |
| GO-2022-0189 | CVE-2018-16873 | Remote command execution via "go get" with "-u" flag in cmd/go | go1.10.6、go1.11.3 |
本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。