Skip to content

Commit b69cacf

Browse files
committed
style: switch tabs to spaces
1 parent 8c9ecfb commit b69cacf

23 files changed

+113
-66
lines changed

src/content/docs/zh-tw/docs/deployment/index.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Gin 專案部署可以透過環境變數或直接在程式碼中進行調整。
4040

4141
以下是可用於設定 Gin 的環境變數:
4242

43-
| 環境變數 | 說明 |
44-
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
45-
| PORT | 使用 `router.Run()` 啟動 Gin 伺服器時要監聽的 TCP 連接埠(即不帶任何參數時)。 |
46-
| GIN_MODE | 可設定為 `debug``release``test`。用於管理 Gin 模式,例如是否輸出除錯資訊。也可以在程式碼中使用 `gin.SetMode(gin.ReleaseMode)``gin.SetMode(gin.TestMode)` 來設定。 |
43+
| 環境變數 | 說明 |
44+
| -------- | -------------------------------------------------------------------- |
45+
| PORT | 使用 `router.Run()` 啟動 Gin 伺服器時要監聽的 TCP 連接埠<br>(即不帶任何參數時)。 |
46+
| GIN_MODE | 可設定為 `debug``release``test`。用於管理 Gin 模式,<br>例如是否輸出除錯資訊。也可以在程式碼中使用<br>`gin.SetMode(gin.ReleaseMode)``gin.SetMode(gin.TestMode)` 來設定。 |
4747

4848
以下程式碼可用於設定 Gin:
4949

@@ -71,9 +71,13 @@ router.SetTrustedProxies([]string{"192.168.1.2"})
7171

7272
Gin 允許您指定哪些標頭可以保存真實的客戶端 IP(如果有的話),以及指定您信任哪些代理(或直接客戶端)可以設定這些標頭。
7373

74-
`gin.Engine` 上使用 `SetTrustedProxies()` 函式來指定可信任的網路位址或網路 CIDR,這些來源的請求標頭中與客戶端 IP 相關的資訊將被視為可信任。可以是 IPv4 位址、IPv4 CIDR、IPv6 位址或 IPv6 CIDR。
74+
`gin.Engine` 上使用 `SetTrustedProxies()` 函式來指定可信任的網路位址或網路 CIDR,
75+
這些來源的請求標頭中與客戶端 IP 相關的資訊將被視為可信任。
76+
可以是 IPv4 位址、IPv4 CIDR、IPv6 位址或 IPv6 CIDR。
7577

76-
**注意:** 如果您沒有使用上述函式指定可信任的代理,Gin 預設會信任所有代理,這是**不安全的**。同時,如果您不使用任何代理,可以使用 `Engine.SetTrustedProxies(nil)` 來停用此功能,這樣 `Context.ClientIP()` 將直接回傳遠端位址,避免不必要的運算。
78+
**注意:** 如果您沒有使用上述函式指定可信任的代理,Gin 預設會信任所有代理,
79+
這是**不安全的**。同時,如果您不使用任何代理,可以使用 `Engine.SetTrustedProxies(nil)`
80+
來停用此功能,這樣 `Context.ClientIP()` 將直接回傳遠端位址,避免不必要的運算。
7781

7882
```go
7983
import (
@@ -96,7 +100,8 @@ Gin 允許您指定哪些標頭可以保存真實的客戶端 IP(如果有的
96100
}
97101
```
98102

99-
**提醒:** 如果您使用 CDN 服務,可以設定 `Engine.TrustedPlatform` 來跳過 TrustedProxies 檢查,它的優先順序高於 TrustedProxies。
103+
**提醒:** 如果您使用 CDN 服務,可以設定 `Engine.TrustedPlatform`
104+
來跳過 TrustedProxies 檢查,它的優先順序高於 TrustedProxies。
100105
請看以下範例:
101106

102107
```go

src/content/docs/zh-tw/docs/examples/bind-body-into-dirrerent-structs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ func SomeHandler(c *gin.Context) {
5757
```
5858

5959
* `c.ShouldBindBodyWith` 會在綁定前將內文儲存到上下文中。這對效能有輕微影響,因此如果您只需呼叫一次綁定,則不應使用此方法。
60-
* 此功能僅適用於某些格式——`JSON``XML``MsgPack``ProtoBuf`。對於其他格式,如 `Query``Form``FormPost``FormMultipart`,可以多次呼叫 `c.ShouldBind()` 而不會對效能造成任何損害(請參閱 [#1341](https://github.com/gin-gonic/gin/pull/1341))。
60+
* 此功能僅適用於某些格式——`JSON``XML``MsgPack``ProtoBuf`
61+
對於其他格式,如 `Query``Form``FormPost``FormMultipart`
62+
可以多次呼叫 `c.ShouldBind()` 而不會對效能造成任何損害(請參閱 [#1341](https://github.com/gin-gonic/gin/pull/1341))。

src/content/docs/zh-tw/docs/examples/bind-single-binary-with-template.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ func loadTemplate() (*template.Template, error) {
5151
}
5252
```
5353

54-
請參閱 [assets-in-binary/example01](https://github.com/gin-gonic/examples/tree/master/assets-in-binary/example01) 目錄中的完整範例。
54+
請參閱
55+
[assets-in-binary/example01](https://github.com/gin-gonic/examples/tree/master/assets-in-binary/example01)
56+
目錄中的完整範例。

src/content/docs/zh-tw/docs/examples/binding-and-validation.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ title: "模型綁定與驗證"
44

55
若要將請求內文綁定到一個類型,請使用模型綁定。我們目前支援綁定 JSON、XML、YAML 和標準表單值 (foo=bar&boo=baz)。
66

7-
Gin 使用 [**go-playground/validator/v10**](https://github.com/go-playground/validator) 進行驗證。請在此處查看有關標籤用法的[完整文件](https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Baked_In_Validators_and_Tags)
7+
Gin 使用 [**go-playground/validator/v10**](https://github.com/go-playground/validator)
8+
進行驗證。請在此處查看有關標籤用法的[完整文件](https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Baked_In_Validators_and_Tags)
89

910
請注意,您需要在所有要綁定的欄位上設定對應的綁定標籤。例如,從 JSON 綁定時,請設定 `json:"fieldname"`
1011

1112
此外,Gin 還提供了兩組綁定方法:
1213

1314
- **類型** - 必須綁定
1415
- **方法** - `Bind``BindJSON``BindXML``BindQuery``BindYAML`
15-
- **行為** - 這些方法在底層使用 `MustBindWith`。如果發生綁定錯誤,請求將被中止,並回傳 `c.AbortWithError(400, err).SetType(ErrorTypeBind)`。這會將回應狀態碼設定為 400,並將 `Content-Type` 標頭設定為 `text/plain; charset=utf-8`。請注意,如果您在此之後嘗試設定回應碼,將會出現警告 `[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 422`。如果您希望對行為有更大的控制權,請考慮使用 `ShouldBind` 的對等方法。
16+
- **行為** - 這些方法在底層使用 `MustBindWith`
17+
如果發生綁定錯誤,請求將被中止,並回傳 `c.AbortWithError(400, err).SetType(ErrorTypeBind)`
18+
這會將回應狀態碼設定為 400,並將 `Content-Type` 標頭設定為 `text/plain; charset=utf-8`
19+
請注意,如果您在此之後嘗試設定回應碼,將會出現警告
20+
`[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 422`
21+
如果您希望對行為有更大的控制權,請考慮使用 `ShouldBind` 的對等方法。
1622
- **類型** - 應該綁定
1723
- **方法** - `ShouldBind``ShouldBindJSON``ShouldBindXML``ShouldBindQuery``ShouldBindYAML`
1824
- **行為** - 這些方法在底層使用 `ShouldBindWith`。如果發生綁定錯誤,將會回傳錯誤,開發人員有責任適當處理請求和錯誤。
@@ -121,4 +127,6 @@ $ curl -v -X POST \
121127

122128
#### 略過驗證
123129

124-
使用上述 `curl` 指令執行範例時,會回傳錯誤。這是因為範例中 `Password` 使用了 `binding:"required"`。如果將 `Password` 的標籤改為 `binding:"-"`,再次執行上述範例時將不會回傳錯誤。
130+
使用上述 `curl` 指令執行範例時,會回傳錯誤。
131+
這是因為範例中 `Password` 使用了 `binding:"required"`
132+
如果將 `Password` 的標籤改為 `binding:"-"`,再次執行上述範例時將不會回傳錯誤。

src/content/docs/zh-tw/docs/examples/custom-validators.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
// Booking 包含已綁定和已驗證的資料。
2121
type Booking struct {
2222
CheckIn time.Time `form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"`
23-
CheckOut time.Time `form:"check_out" binding:"required,gtfield=CheckIn,bookabledate" time_format:"2006-01-02"`
23+
CheckOut time.Time `form:"check_out" binding:"required,gtfield=CheckIn,bookabledate"
24+
time_format:"2006-01-02"`
2425
}
2526

2627
func bookableDate(

src/content/docs/zh-tw/docs/examples/define-format-for-the-log-of-routes.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ title: "定義路由日誌的格式"
33
---
44

55
路由的預設日誌如下:
6-
```
6+
7+
```sh
78
[GIN-debug] POST /foo --> main.main.func1 (3 handlers)
89
[GIN-debug] GET /bar --> main.main.func2 (3 handlers)
910
[GIN-debug] GET /status --> main.main.func3 (3 handlers)
1011
```
1112

12-
如果您想以給定的格式(例如 JSON、鍵值對或其他格式)記錄此資訊,您可以使用 `gin.DebugPrintRouteFunc` 定義此格式。
13-
在下面的範例中,我們使用標準日誌套件記錄所有路由,但您也可以使用適合您需求的其他日誌工具。
13+
如果您想以給定的格式(例如 JSON、鍵值對或其他格式)記錄此資訊,
14+
您可以使用 `gin.DebugPrintRouteFunc` 定義此格式。
15+
在下面的範例中,我們使用標準日誌套件記錄所有路由,
16+
但您也可以使用適合您需求的其他日誌工具。
17+
1418
```go
1519
import (
1620
"log"

src/content/docs/zh-tw/docs/examples/graceful-restart-or-stop.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ title: "優雅地重新啟動或停止"
55
您想要優雅地重新啟動或停止您的網頁伺服器嗎?
66
有幾種方法可以做到。
77

8-
我們可以使用 [fvbock/endless](https://github.com/fvbock/endless) 來取代預設的 `ListenAndServe`。詳情請參閱問題 [#296](https://github.com/gin-gonic/gin/issues/296)
8+
我們可以使用 [fvbock/endless](https://github.com/fvbock/endless)
9+
來取代預設的 `ListenAndServe`。詳情請參閱問題
10+
[#296](https://github.com/gin-gonic/gin/issues/296)
911

1012
```go
1113
import (
@@ -28,10 +30,13 @@ func main() {
2830
endless 的替代方案:
2931

3032
* [manners](https://github.com/braintree/manners):一個能優雅關閉的 Go HTTP 伺服器。
31-
* [graceful](https://github.com/tylerb/graceful):Graceful 是一個 Go 套件,可讓 http.Handler 伺服器優雅關閉。
33+
* [graceful](https://github.com/tylerb/graceful):Graceful 是一個 Go
34+
套件,可讓 http.Handler 伺服器優雅關閉。
3235
* [grace](https://github.com/facebookgo/grace):Go 伺服器的優雅重啟與零停機部署。
3336

34-
如果您使用 Go 1.8 或更新版本,您可能不需要使用此函式庫!請考慮使用 `http.Server` 內建的 [Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown) 方法來進行優雅關閉。請參閱 gin 的完整[優雅關閉](https://github.com/gin-gonic/examples/tree/master/graceful-shutdown)範例。
37+
如果您使用 Go 1.8 或更新版本,您可能不需要使用此函式庫!請考慮使用 `http.Server`
38+
內建的 [Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown)
39+
方法來進行優雅關閉。請參閱 gin 的完整[優雅關閉](https://github.com/gin-gonic/examples/tree/master/graceful-shutdown)範例。
3540

3641
```go
3742
//go:build go1.8
@@ -88,4 +93,3 @@ func main() {
8893
log.Println("伺服器已退出")
8994
}
9095
```
91-

src/content/docs/zh-tw/docs/examples/html-rendering.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ raw.tmpl
156156
```
157157

158158
結果:
159+
159160
```sh
160161
日期: 2017/07/01
161162
```

src/content/docs/zh-tw/docs/examples/http2-server-push.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ func main() {
4747
router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key")
4848
}
4949
```
50-

src/content/docs/zh-tw/docs/examples/map-as-querystring-or-postform.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ func main() {
3333
```sh
3434
ids: map[b:hello a:1234], names: map[second:tianou first:thinkerou]
3535
```
36-

0 commit comments

Comments
 (0)