Skip to content

Commit 318888e

Browse files
committed
style: switch tabs to spaces
1 parent 95dbd8d commit 318888e

36 files changed

+398
-124
lines changed

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

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Qovery 提供免費的雲端主機托管,包括資料庫、SSL、全球 CDN,
2222

2323
Render 是一個原生支援 Go 語言的現代化雲平台,並支持管理 SSL、資料庫、不停機部署、HTTP/2 和 websocket。
2424

25-
請參考 Render 文件[部署 Gin 專案](https://render.com/docs/deploy-go-gin).
25+
請參考 Render 文件[部署 Gin 專案](https://render.com/docs/deploy-go-gin)
2626

2727
## [Google App Engine](https://cloud.google.com/appengine/)
2828

@@ -76,55 +76,55 @@ Gin 允許您指定哪些標頭可以保存真實的客戶端 IP(如果有的
7676
**注意:** 如果您沒有使用上述函式指定可信任的代理,Gin 預設會信任所有代理,這是**不安全的**。同時,如果您不使用任何代理,可以使用 `Engine.SetTrustedProxies(nil)` 來停用此功能,這樣 `Context.ClientIP()` 將直接回傳遠端位址,避免不必要的運算。
7777

7878
```go
79-
import (
80-
"fmt"
81-
82-
"github.com/gin-gonic/gin"
83-
)
84-
85-
func main() {
86-
router := gin.Default()
87-
router.SetTrustedProxies([]string{"192.168.1.2"})
88-
89-
router.GET("/", func(c *gin.Context) {
90-
// 如果客戶端是 192.168.1.2,則使用 X-Forwarded-For
91-
// 標頭中可信任的部分來推斷原始客戶端 IP。
92-
// 否則,直接回傳客戶端 IP
93-
fmt.Printf("ClientIP: %s\n", c.ClientIP())
94-
})
95-
router.Run()
96-
}
79+
import (
80+
"fmt"
81+
82+
"github.com/gin-gonic/gin"
83+
)
84+
85+
func main() {
86+
router := gin.Default()
87+
router.SetTrustedProxies([]string{"192.168.1.2"})
88+
89+
router.GET("/", func(c *gin.Context) {
90+
// 如果客戶端是 192.168.1.2,則使用 X-Forwarded-For
91+
// 標頭中可信任的部分來推斷原始客戶端 IP。
92+
// 否則,直接回傳客戶端 IP
93+
fmt.Printf("ClientIP: %s\n", c.ClientIP())
94+
})
95+
router.Run()
96+
}
9797
```
9898

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

102102
```go
103-
import (
104-
"fmt"
105-
106-
"github.com/gin-gonic/gin"
107-
)
108-
109-
func main() {
110-
router := gin.Default()
111-
// 使用預定義的標頭 gin.PlatformXXX
112-
// Google App Engine
113-
router.TrustedPlatform = gin.PlatformGoogleAppEngine
114-
// Cloudflare
115-
router.TrustedPlatform = gin.PlatformCloudflare
116-
// Fly.io
117-
router.TrustedPlatform = gin.PlatformFlyIO
118-
// 或者,您可以設定自己的可信任請求標頭。但請確保您的 CDN
119-
// 會防止使用者傳遞此標頭!例如,如果您的 CDN 將客戶端 IP
120-
// 放在 X-CDN-Client-IP 中:
121-
router.TrustedPlatform = "X-CDN-Client-IP"
122-
123-
router.GET("/", func(c *gin.Context) {
124-
// 如果您設定了 TrustedPlatform,ClientIP() 將會解析
125-
// 對應的標頭並直接回傳 IP
126-
fmt.Printf("ClientIP: %s\n", c.ClientIP())
127-
})
128-
router.Run()
129-
}
103+
import (
104+
"fmt"
105+
106+
"github.com/gin-gonic/gin"
107+
)
108+
109+
func main() {
110+
router := gin.Default()
111+
// 使用預定義的標頭 gin.PlatformXXX
112+
// Google App Engine
113+
router.TrustedPlatform = gin.PlatformGoogleAppEngine
114+
// Cloudflare
115+
router.TrustedPlatform = gin.PlatformCloudflare
116+
// Fly.io
117+
router.TrustedPlatform = gin.PlatformFlyIO
118+
// 或者,您可以設定自己的可信任請求標頭。但請確保您的 CDN
119+
// 會防止使用者傳遞此標頭!例如,如果您的 CDN 將客戶端 IP
120+
// 放在 X-CDN-Client-IP 中:
121+
router.TrustedPlatform = "X-CDN-Client-IP"
122+
123+
router.GET("/", func(c *gin.Context) {
124+
// 如果您設定了 TrustedPlatform,ClientIP() 將會解析
125+
// 對應的標頭並直接回傳 IP
126+
fmt.Printf("ClientIP: %s\n", c.ClientIP())
127+
})
128+
router.Run()
129+
}
130130
```

src/content/docs/zh-tw/docs/examples/ascii-json.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ title: "AsciiJSON"
55
使用 AsciiJSON 來產生僅含 ASCII 字元並逸出非 ASCII 字元的 JSON。
66

77
```go
8+
import (
9+
"net/http"
10+
11+
"github.com/gin-gonic/gin"
12+
)
13+
814
func main() {
915
router := gin.Default()
1016

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func SomeHandler(c *gin.Context) {
3131
為此,您可以使用 `c.ShouldBindBodyWith`
3232

3333
```go
34+
import (
35+
"net/http"
36+
37+
"github.com/gin-gonic/gin"
38+
"github.com/gin-gonic/gin/binding"
39+
)
40+
3441
func SomeHandler(c *gin.Context) {
3542
objA := formA{}
3643
objB := formB{}

src/content/docs/zh-tw/docs/examples/bind-html-checkbox.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,33 @@ title: "綁定 HTML 核取方塊"
77
main.go
88

99
```go
10-
...
10+
import (
11+
"net/http"
12+
13+
"github.com/gin-gonic/gin"
14+
)
1115

1216
type myForm struct {
1317
Colors []string `form:"colors[]"`
1418
}
1519

16-
...
20+
func main() {
21+
router := gin.Default()
22+
router.GET("/", func(c *gin.Context) {
23+
c.HTML(http.StatusOK, "form.html", nil)
24+
})
25+
router.POST("/", formHandler)
26+
router.LoadHTMLFiles("form.html")
27+
28+
router.Run()
29+
}
1730

1831
func formHandler(c *gin.Context) {
1932
var fakeForm myForm
2033
c.ShouldBind(&fakeForm)
21-
c.JSON(200, gin.H{"color": fakeForm.Colors})
34+
c.JSON(http.StatusOK, gin.H{"color": fakeForm.Colors})
2235
}
2336

24-
...
25-
2637
```
2738

2839
form.html

src/content/docs/zh-tw/docs/examples/bind-query-or-post.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ title: "綁定查詢字串或 POST 資料"
77
```go
88
package main
99

10-
import (
11-
"log"
12-
"time"
10+
import (
11+
"log"
12+
"time"
1313

14-
"github.com/gin-gonic/gin"
15-
)
14+
"github.com/gin-gonic/gin"
15+
)
1616

1717
type Person struct {
1818
Name string `form:"name"`

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ title: "使用樣板建置單一二進位檔"
77
[go-assets]: https://github.com/jessevdk/go-assets
88

99
```go
10+
import (
11+
"html/template"
12+
"io/ioutil"
13+
"net/http"
14+
"strings"
15+
16+
"github.com/gin-gonic/gin"
17+
)
18+
1019
func main() {
1120
r := gin.New()
1221

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ type Login struct {
2828
Password string `form:"password" json:"password" xml:"password" binding:"required"`
2929
}
3030

31+
import (
32+
"net/http"
33+
34+
"github.com/gin-gonic/gin"
35+
)
36+
3137
func main() {
3238
router := gin.Default()
3339

src/content/docs/zh-tw/docs/examples/cookie.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ title: "Cookie"
66

77
```go
88
import (
9-
"fmt"
9+
"fmt"
1010

11-
"github.com/gin-gonic/gin"
11+
"github.com/gin-gonic/gin"
1212
)
1313

1414
func main() {
1515

16-
router := gin.Default()
16+
router := gin.Default()
1717

18-
router.GET("/cookie", func(c *gin.Context) {
18+
router.GET("/cookie", func(c *gin.Context) {
1919

20-
cookie, err := c.Cookie("gin_cookie")
20+
cookie, err := c.Cookie("gin_cookie")
2121

22-
if err != nil {
23-
cookie = "NotSet"
24-
c.SetCookie("gin_cookie", "test", 3600, "/", "localhost", false, true)
25-
}
22+
if err != nil {
23+
cookie = "NotSet"
24+
c.SetCookie("gin_cookie", "test", 3600, "/", "localhost", false, true)
25+
}
2626

27-
fmt.Printf("Cookie 值:%s \n", cookie)
28-
})
27+
fmt.Printf("Cookie 值:%s \n", cookie)
28+
})
2929

30-
router.Run()
30+
router.Run()
3131
}
3232
```
3333

src/content/docs/zh-tw/docs/examples/custom-http-config.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ func main() {
1515
1616

1717
```go
18-
import "net/http"
18+
import (
19+
"net/http"
20+
"time"
21+
22+
"github.com/gin-gonic/gin"
23+
)
1924

2025
func main() {
2126
router := gin.Default()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ title: "自訂中介軟體"
33
---
44

55
```go
6+
import (
7+
"log"
8+
"time"
9+
10+
"github.com/gin-gonic/gin"
11+
)
12+
613
func Logger() gin.HandlerFunc {
714
return func(c *gin.Context) {
815
t := time.Now()

0 commit comments

Comments
 (0)