Go 1.6

最後更新


Go 1.6 發布於 2016-02-17,目前最新修補版為 go1.6.4,已停止支援,請升級到 go1.27.4。

版本介紹


Go 1.6 沒有語言變更。最有感的兩件事:net/http 在 HTTPS 下自動支援 HTTP/2,程式不用改一行;vendoring 正式成為預設功能,專案可以把依賴放在 vendor 目錄裡一起管理。此外也正式訂定 Go 與 C 之間共用指標的規則,並由執行時檢查。

工具


  • vendoring 預設啟用,不再是實驗功能(仍可用 GO15VENDOREXPERIMENT=0 關閉)。
  • cgo 訂定指標傳遞規則:傳給 C 的 Go 記憶體不得再含有指向 Go 記憶體的指標,C 也不能在呼叫結束後保留指標;違反時執行時會直接當掉並說明原因。
  • go vet 會檢查把函式值本身(而非呼叫結果)傳給 Printf 的錯誤;go build 新增 -msan(LLVM 記憶體檢查工具)支援。
  • 新增 Linux 64 位元 MIPS 與 Android 32 位元 x86 平台。

執行時與效能


  • 執行時加入輕量的映射並行誤用偵測:一邊寫、一邊有其他 goroutine 讀寫同一個映射時,程式會直接終止並印出診斷。
  • 程式因 panic 結束時,預設只印出當前 goroutine 的堆疊,輸出更精簡;需要全部時設定 GOTRACEBACK=all。
  • 垃圾回收暫停時間比 1.5 更低,大量使用記憶體的程式尤其明顯。
  • compress/gzip、crypto/aes、sort 等套件效能提升超過 10%。

標準庫重點


  • net/http 在 HTTPS 下自動協商 HTTP/2,用戶端與伺服器端皆然。
  • text/template 新增 {{-、-}} 去除動作(action)前後的空白,並新增 {{block}} 定義可被覆寫的預設區塊。
  • sort.Sort 改寫,比較與交換次數減少約 10%;相等元素的最終順序可能和以前不同,需要保留原順序請用 sort.Stable。

樣板空白修剪與 block


{{- 會去掉動作前面的空白與換行,-}} 去掉後面的。{{block "name" .}} 等於「定義並立刻執行」一個樣板,之後可以用 {{define}} 換掉它的內容。
  1. package main
  2. import (
  3. "os"
  4. "text/template"
  5. )
  6. const page = `{{define "title"}}預設標題{{end -}}
  7. <h1>{{block "title" .}}{{end}}</h1>
  8. <ul>
  9. {{- range .}}
  10. <li>{{.}}</li>
  11. {{- end}}
  12. </ul>
  13. `
  14. func main() {
  15. t := template.Must(template.New("page").Parse(page))
  16. t.Execute(os.Stdout, []string{"apple", "banana"})
  17. custom := template.Must(template.Must(t.Clone()).Parse(`{{define "title"}}水果清單{{end}}`))
  18. custom.Execute(os.Stdout, []string{"cherry"})
  19. }

  1. <h1>預設標題</h1>
  2. <ul>
  3. <li>apple</li>
  4. <li>banana</li>
  5. </ul>
  6. <h1>水果清單</h1>
  7. <ul>
  8. <li>cherry</li>
  9. </ul>

本版新增的棄用 API


以下 API 從 Go 1.6 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
套件符號官方說明
compress/flateReadErrorNo longer returned.
compress/flateWriteErrorNo longer returned.
net/httpTransport.CancelRequestUse [Request.WithContext] to create a request with a cancelable context instead. CancelRequest cannot cancel HTTP/2 requests. This may become a no-op in a future release of Go.

修補版本


版本發布日期含安全修補內容(官方原文)
go1.6.12016-04-12是includes two security fixes.
go1.6.22016-04-20否includes fixes to the compiler, runtime, tools, documentation, and the mime/multipart, net/http, and sort packages.
go1.6.32016-07-17是includes security fixes to the net/http/cgi package and net/http package when used in a CGI environment.
go1.6.42016-12-01是includes two security fixes. It contains the same fixes as Go 1.7.4 and was released at the same time.

已知漏洞


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

本系列已修正


編號CVE摘要(官方原文)修正於
GO-2022-0761CVE-2016-5386Improper input validation in net/http and net/http/cgigo1.6.3
GO-2022-0171CVE-2017-1000097Mishandled trust preferences for root certificates on Darwin in crypto/x509go1.6.4、go1.7.4
GO-2022-0166CVE-2016-3959Denial of service due to unchecked parameters in crypto/dsago1.5.4、go1.6.1
GO-2021-0172CVE-2017-1000098Denial of service when parsing large forms in mime/multipartgo1.6.4、go1.7.4
GO-2021-0163CVE-2016-3958Privilege escalation on Windows via malicious DLL in syscallgo1.5.4、go1.6.1

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

資料來源