# 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` 用過之後不能複製。

```go
package main

import (
	"fmt"
	"strings"
)

func main() {
	var b strings.Builder
	for i := 1; i <= 3; i++ {
		fmt.Fprintf(&b, "item-%d;", i)
	}
	b.WriteString("done")
	fmt.Println(b.String())
	fmt.Println(b.Len())
}
```

```text
item-1;item-2;item-3;done
25
```

## 本版新增的棄用 API

以下 API 從 Go 1.10 起標記為棄用（Deprecated），新程式不要再使用；說明欄為官方原文。

| 套件 | 符號 | 官方說明 |
| --- | --- | --- |
| `archive/tar` | `Header.Xattrs` | Use PAXRecords instead. |
| `archive/zip` | `FileHeader.ModTime` | Use [Modified] instead. |
| `archive/zip` | `FileHeader.ModifiedDate` | Use Modified instead. |
| `archive/zip` | `FileHeader.ModifiedTime` | Use Modified instead. |
| `archive/zip` | `FileHeader.SetModTime` | Use [Modified] instead. |
| `encoding/csv` | `ErrTrailingComma` | ErrTrailingComma is no longer used. |
| `encoding/csv` | `Reader.TrailingComma` | TrailingComma is no longer used. |

## 修補版本

| 版本 | 發布日期 | 含安全修補 | 內容（官方原文） |
| --- | --- | --- | --- |
| `go1.10.1` | 2018-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.2` | 2018-05-01 | 否 | includes fixes to the compiler, linker, and go command. |
| `go1.10.3` | 2018-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.4` | 2018-08-24 | 否 | includes fixes to the go command, linker, and the bytes, mime/multipart, net/http, and strings packages. |
| `go1.10.5` | 2018-11-02 | 否 | includes fixes to the go command, linker, runtime, and the database/sql package. |
| `go1.10.6` | 2018-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.7` | 2018-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.8` | 2019-01-23 | 是 | includes a security fix to the crypto/elliptic package. |

## 已知漏洞

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

### 本系列已修正

| 編號 | CVE | 摘要（官方原文） | 修正於 |
| --- | --- | --- | --- |
| [GO-2022-0217](https://pkg.go.dev/vuln/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-0203](https://pkg.go.dev/vuln/GO-2022-0203) | CVE-2018-7187 | Remote command execution via "go get" command with "-insecure" option in cmd/go | go1.9.5、go1.10.1 |
| [GO-2022-0191](https://pkg.go.dev/vuln/GO-2022-0191) | CVE-2018-16875 | Denial of service in chain verification in crypto/x509 | go1.10.6、go1.11.3 |
| [GO-2022-0190](https://pkg.go.dev/vuln/GO-2022-0190) | CVE-2018-16874 | Directory traversal via "go get" command in cmd/go | go1.10.6、go1.11.3 |
| [GO-2022-0189](https://pkg.go.dev/vuln/GO-2022-0189) | CVE-2018-16873 | Remote command execution via "go get" with "-u" flag in cmd/go | go1.10.6、go1.11.3 |

本版已停止支援，不會再修正這些漏洞；完整清單見 [資安漏洞](/security)。


## 資料來源

- [Go 1.10 Release Notes](https://go.dev/doc/go1.10)
- [Go 發版歷史](https://go.dev/doc/devel/release#go1.10)
- [Go 漏洞資料庫](https://vuln.go.dev)
- [golang/go 原始碼 go1.10](https://github.com/golang/go/tree/go1.10)
