diff --git a/content/en/docs/examples/ascii-json.md b/content/en/docs/examples/ascii-json.md index 82ab48d2a..d8e62319f 100644 --- a/content/en/docs/examples/ascii-json.md +++ b/content/en/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ Using AsciiJSON to Generates ASCII-only JSON with escaped non-ASCII characters. ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/bind-form-data-request-with-custom-struct.md b/content/en/docs/examples/bind-form-data-request-with-custom-struct.md index 2882e8656..7286ea4f9 100644 --- a/content/en/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/en/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/en/docs/examples/bind-single-binary-with-template.md b/content/en/docs/examples/bind-single-binary-with-template.md index 36f0bb212..eab489293 100644 --- a/content/en/docs/examples/bind-single-binary-with-template.md +++ b/content/en/docs/examples/bind-single-binary-with-template.md @@ -14,12 +14,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate loads templates embedded by go-assets-builder diff --git a/content/en/docs/examples/custom-middleware.md b/content/en/docs/examples/custom-middleware.md index dd7407b07..3e87bf2f0 100644 --- a/content/en/docs/examples/custom-middleware.md +++ b/content/en/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // it would print: "12345" @@ -37,7 +37,7 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/define-format-for-the-log-of-routes.md b/content/en/docs/examples/define-format-for-the-log-of-routes.md index 6cfdaa68f..7d101aa89 100644 --- a/content/en/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/en/docs/examples/define-format-for-the-log-of-routes.md @@ -21,24 +21,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // Listen and Server in http://0.0.0.0:8080 - r.Run() + router.Run() } ``` diff --git a/content/en/docs/examples/goroutines-inside-a-middleware.md b/content/en/docs/examples/goroutines-inside-a-middleware.md index 122593a1b..1461c9626 100644 --- a/content/en/docs/examples/goroutines-inside-a-middleware.md +++ b/content/en/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // create copy to be used inside the goroutine cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // simulate a long task with time.Sleep(). 5 seconds time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/html-rendering.md b/content/en/docs/examples/html-rendering.md index cfa8e825a..388f08560 100644 --- a/content/en/docs/examples/html-rendering.md +++ b/content/en/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { You may use custom delims ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### Custom Template Funcs diff --git a/content/en/docs/examples/http2-server-push.md b/content/en/docs/examples/http2-server-push.md index 83649a407..bc39b8ad8 100644 --- a/content/en/docs/examples/http2-server-push.md +++ b/content/en/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // use pusher.Push() to do server push if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // Listen and Serve in https://127.0.0.1:8080 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/en/docs/examples/jsonp.md b/content/en/docs/examples/jsonp.md index 63c7dc551..e88fb3146 100644 --- a/content/en/docs/examples/jsonp.md +++ b/content/en/docs/examples/jsonp.md @@ -7,9 +7,9 @@ Using JSONP to request data from a server in a different domain. Add callback t ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/pure-json.md b/content/en/docs/examples/pure-json.md index d91f905ef..e5205fe40 100644 --- a/content/en/docs/examples/pure-json.md +++ b/content/en/docs/examples/pure-json.md @@ -8,23 +8,23 @@ This feature is unavailable in Go 1.6 and lower. ```go func main() { - r := gin.Default() + router := gin.Default() // Serves unicode entities - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // Serves literal characters - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/redirects.md b/content/en/docs/examples/redirects.md index f7d823eca..b32e96563 100644 --- a/content/en/docs/examples/redirects.md +++ b/content/en/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false Issuing a HTTP redirect is easy. Both internal and external locations are supported. ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Issuing a Router redirect, use `HandleContext` like below. ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/en/docs/examples/rendering.md b/content/en/docs/examples/rendering.md index a9fa75b5f..f88ef732c 100644 --- a/content/en/docs/examples/rendering.md +++ b/content/en/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H is a shortcut for map[string]interface{} - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // The specific definition of protobuf is written in the testdata/protoexample file. @@ -49,6 +49,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/secure-json.md b/content/en/docs/examples/secure-json.md index 9f5642167..5cbdbf210 100644 --- a/content/en/docs/examples/secure-json.md +++ b/content/en/docs/examples/secure-json.md @@ -7,12 +7,12 @@ Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to re ```go func main() { - r := gin.Default() + router := gin.Default() // You can also use your own secure json prefix - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // Will output : while(1);["lena","austin","foo"] @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/support-lets-encrypt.md b/content/en/docs/examples/support-lets-encrypt.md index c66288e87..82044829c 100644 --- a/content/en/docs/examples/support-lets-encrypt.md +++ b/content/en/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/en/docs/examples/using-basicauth-middleware.md b/content/en/docs/examples/using-basicauth-middleware.md index 318aca232..b3bc885ca 100644 --- a/content/en/docs/examples/using-basicauth-middleware.md +++ b/content/en/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // Group using gin.BasicAuth() middleware // gin.Accounts is a shortcut for map[string]string - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/examples/using-middleware.md b/content/en/docs/examples/using-middleware.md index 2a3159cc3..92c23d828 100644 --- a/content/en/docs/examples/using-middleware.md +++ b/content/en/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // Global middleware // Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release. // By default gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery middleware recovers from any panics and writes a 500 if there was one. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // Per route middleware, you can add as many as you desire. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // Authorization group - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // exactly the same as: - authorized := r.Group("/") + authorized := router.Group("/") // per group middleware! in this case we use the custom created // AuthRequired() middleware just in the "authorized" group. authorized.Use(AuthRequired()) @@ -37,7 +37,7 @@ func main() { } // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/en/docs/quickstart/_index.md b/content/en/docs/quickstart/_index.md index f8549bb19..c7af2dadb 100644 --- a/content/en/docs/quickstart/_index.md +++ b/content/en/docs/quickstart/_index.md @@ -69,13 +69,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // listen and serve on 0.0.0.0:8080 + router.Run() // listen and serve on 0.0.0.0:8080 } ``` diff --git a/content/en/docs/testing/_index.md b/content/en/docs/testing/_index.md index d8094d084..1eaabebd4 100644 --- a/content/en/docs/testing/_index.md +++ b/content/en/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/ascii-json.md b/content/es/docs/examples/ascii-json.md index 5927cc3f3..3f517fc52 100644 --- a/content/es/docs/examples/ascii-json.md +++ b/content/es/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ Uso de AsciiJSON para generar respuestas JSON únicamente con caracteres ASCII y ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // Escucha y sirve peticiones en 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/bind-form-data-request-with-custom-struct.md b/content/es/docs/examples/bind-form-data-request-with-custom-struct.md index 0d4380157..0a4e08a0c 100644 --- a/content/es/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/es/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/es/docs/examples/bind-single-binary-with-template.md b/content/es/docs/examples/bind-single-binary-with-template.md index 6675a83a9..195632c91 100644 --- a/content/es/docs/examples/bind-single-binary-with-template.md +++ b/content/es/docs/examples/bind-single-binary-with-template.md @@ -13,12 +13,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate carga templates incrustadas por medio de go-assets-builder diff --git a/content/es/docs/examples/custom-middleware.md b/content/es/docs/examples/custom-middleware.md index 45266d215..a72969cfd 100644 --- a/content/es/docs/examples/custom-middleware.md +++ b/content/es/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // debe retornar: "12345" @@ -37,7 +37,7 @@ func main() { }) // Escucha y sirve peticiones en 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/define-format-for-the-log-of-routes.md b/content/es/docs/examples/define-format-for-the-log-of-routes.md index 6f7105dbd..8752a64a8 100644 --- a/content/es/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/es/docs/examples/define-format-for-the-log-of-routes.md @@ -22,24 +22,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // Escucha y sirve peticiones en 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/goroutines-inside-a-middleware.md b/content/es/docs/examples/goroutines-inside-a-middleware.md index 0f27de56b..457470ff7 100644 --- a/content/es/docs/examples/goroutines-inside-a-middleware.md +++ b/content/es/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ Cuando se inicia una goroutine dentro de un middleware o un handler, **NO SE DEB ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // crear una copia para usar dentro de la rutina cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // se simula una tarea prolongada con un time.Sleep(). de 5 seconds time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // Escucha y sirve peticiones en 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/html-rendering.md b/content/es/docs/examples/html-rendering.md index c7b50da78..22c8ae992 100644 --- a/content/es/docs/examples/html-rendering.md +++ b/content/es/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { Pueden establecerse separadores personalizados ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### Funciones personalizadas en plantillas diff --git a/content/es/docs/examples/http2-server-push.md b/content/es/docs/examples/http2-server-push.md index 2ffda0094..2916a7744 100644 --- a/content/es/docs/examples/http2-server-push.md +++ b/content/es/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // Utilice pusher.Push() para hacer server push if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // Escucha y sirve peticiones en https://127.0.0.1:8080 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/es/docs/examples/jsonp.md b/content/es/docs/examples/jsonp.md index 2a05c314d..65d67a9d8 100644 --- a/content/es/docs/examples/jsonp.md +++ b/content/es/docs/examples/jsonp.md @@ -8,9 +8,9 @@ Using JSONP to request data from a server in a different domain. Agregue un cal ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -21,6 +21,6 @@ func main() { }) // Escucha y sirve peticiones en 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/pure-json.md b/content/es/docs/examples/pure-json.md index e879e8503..423bbe504 100644 --- a/content/es/docs/examples/pure-json.md +++ b/content/es/docs/examples/pure-json.md @@ -7,24 +7,24 @@ Esta característica no está disponible en Go 1.6 o versiones inferiores. ```go func main() { - r := gin.Default() + router := gin.Default() // Sirve entidades unicode - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // Sirve carácteres literales - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // Escucha y sirve peticiones en 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/redirects.md b/content/es/docs/examples/redirects.md index c8ede1c6a..e4a8870b8 100644 --- a/content/es/docs/examples/redirects.md +++ b/content/es/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false Emitir una redirección HTTP es sencillo. Son soportadas las rutas internas o externas. ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Emitir una redirección HTTP desde POST. Véase en el issue: [#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Emitir una redirección hacia un Router, puede emplearse `HandleContext` como en el ejemplo inferior. ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/es/docs/examples/rendering.md b/content/es/docs/examples/rendering.md index d8f7af21e..051e0fcad 100644 --- a/content/es/docs/examples/rendering.md +++ b/content/es/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H es un método abreviado para map[string]interface{} - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // También puedes usar un struct var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // La definición del protobuf se encuentra escrita en el archivo testdata/protoexample. @@ -48,6 +48,6 @@ func main() { c.ProtoBuf(http.StatusOK, data) }) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/secure-json.md b/content/es/docs/examples/secure-json.md index cc86e613e..f928154cb 100644 --- a/content/es/docs/examples/secure-json.md +++ b/content/es/docs/examples/secure-json.md @@ -6,18 +6,18 @@ Usando SecureJSON para evitar el secuestro de JSON. Por defecto se antepone `"wh ```go func main() { - r := gin.Default() + router := gin.Default() // Se puede emplear un prefijo JSON seguro propio - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // Retornará : while(1);["lena","austin","foo"] c.SecureJSON(http.StatusOK, names) }) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/support-lets-encrypt.md b/content/es/docs/examples/support-lets-encrypt.md index d6b8daa5a..87b8e5945 100644 --- a/content/es/docs/examples/support-lets-encrypt.md +++ b/content/es/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Manejador de Ping - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Manejador de Ping - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/es/docs/examples/using-basicauth-middleware.md b/content/es/docs/examples/using-basicauth-middleware.md index c0e79ff90..a6d664fca 100644 --- a/content/es/docs/examples/using-basicauth-middleware.md +++ b/content/es/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // Agrupación de rutas usando el middleware gin.BasicAuth() // gin.Accounts es una abreviatura para map[string]string - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -35,6 +35,6 @@ func main() { } }) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/examples/using-middleware.md b/content/es/docs/examples/using-middleware.md index 310fc2caa..18534ac43 100644 --- a/content/es/docs/examples/using-middleware.md +++ b/content/es/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // Middleware global // El middlware Logger escribirá los logs hacia gin.DefaultWriter incluso si se configura GIN_MODE=release. // Por defecto será gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // El middleware Recovery recupera al servicio de cualquier panics y registra un error 500 si existiese uno. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // Middleware por ruta, se pueden añadir tantos como sea necesario. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // Grupo de Authorization - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // exactamente el mismo que: - authorized := r.Group("/") + authorized := router.Group("/") // Middleware por grupo. En este caso usamos el grupo creado // y se aplicará AuthRequired() middleware únicamente en el grupo "authorized". authorized.Use(AuthRequired()) @@ -36,7 +36,7 @@ func main() { testing.GET("/analytics", analyticsEndpoint) } - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/es/docs/quickstart/_index.md b/content/es/docs/quickstart/_index.md index 743004adf..805f32da6 100644 --- a/content/es/docs/quickstart/_index.md +++ b/content/es/docs/quickstart/_index.md @@ -69,13 +69,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // Sirve y escucha peticiones en 0.0.0.0:8080 + router.Run() // Sirve y escucha peticiones en 0.0.0.0:8080 } ``` diff --git a/content/es/docs/testing/_index.md b/content/es/docs/testing/_index.md index 31ff24fe6..e0e8201d0 100644 --- a/content/es/docs/testing/_index.md +++ b/content/es/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/ascii-json.md b/content/fa/docs/examples/ascii-json.md index 82ab48d2a..d8e62319f 100644 --- a/content/fa/docs/examples/ascii-json.md +++ b/content/fa/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ Using AsciiJSON to Generates ASCII-only JSON with escaped non-ASCII characters. ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/bind-form-data-request-with-custom-struct.md b/content/fa/docs/examples/bind-form-data-request-with-custom-struct.md index 2882e8656..7286ea4f9 100644 --- a/content/fa/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/fa/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/fa/docs/examples/bind-single-binary-with-template.md b/content/fa/docs/examples/bind-single-binary-with-template.md index 36f0bb212..eab489293 100644 --- a/content/fa/docs/examples/bind-single-binary-with-template.md +++ b/content/fa/docs/examples/bind-single-binary-with-template.md @@ -14,12 +14,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate loads templates embedded by go-assets-builder diff --git a/content/fa/docs/examples/custom-middleware.md b/content/fa/docs/examples/custom-middleware.md index dd7407b07..3e87bf2f0 100644 --- a/content/fa/docs/examples/custom-middleware.md +++ b/content/fa/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // it would print: "12345" @@ -37,7 +37,7 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/define-format-for-the-log-of-routes.md b/content/fa/docs/examples/define-format-for-the-log-of-routes.md index 6cfdaa68f..7d101aa89 100644 --- a/content/fa/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/fa/docs/examples/define-format-for-the-log-of-routes.md @@ -21,24 +21,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // Listen and Server in http://0.0.0.0:8080 - r.Run() + router.Run() } ``` diff --git a/content/fa/docs/examples/goroutines-inside-a-middleware.md b/content/fa/docs/examples/goroutines-inside-a-middleware.md index 122593a1b..1461c9626 100644 --- a/content/fa/docs/examples/goroutines-inside-a-middleware.md +++ b/content/fa/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // create copy to be used inside the goroutine cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // simulate a long task with time.Sleep(). 5 seconds time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/html-rendering.md b/content/fa/docs/examples/html-rendering.md index cfa8e825a..388f08560 100644 --- a/content/fa/docs/examples/html-rendering.md +++ b/content/fa/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { You may use custom delims ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### Custom Template Funcs diff --git a/content/fa/docs/examples/http2-server-push.md b/content/fa/docs/examples/http2-server-push.md index 00bbd12d8..51e0440e8 100644 --- a/content/fa/docs/examples/http2-server-push.md +++ b/content/fa/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // use pusher.Push() to do server push if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // Listen and Server in https://127.0.0.1:8080 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/fa/docs/examples/jsonp.md b/content/fa/docs/examples/jsonp.md index 63c7dc551..e88fb3146 100644 --- a/content/fa/docs/examples/jsonp.md +++ b/content/fa/docs/examples/jsonp.md @@ -7,9 +7,9 @@ Using JSONP to request data from a server in a different domain. Add callback t ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/pure-json.md b/content/fa/docs/examples/pure-json.md index d91f905ef..e5205fe40 100644 --- a/content/fa/docs/examples/pure-json.md +++ b/content/fa/docs/examples/pure-json.md @@ -8,23 +8,23 @@ This feature is unavailable in Go 1.6 and lower. ```go func main() { - r := gin.Default() + router := gin.Default() // Serves unicode entities - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // Serves literal characters - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/redirects.md b/content/fa/docs/examples/redirects.md index f7d823eca..b32e96563 100644 --- a/content/fa/docs/examples/redirects.md +++ b/content/fa/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false Issuing a HTTP redirect is easy. Both internal and external locations are supported. ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Issuing a Router redirect, use `HandleContext` like below. ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/fa/docs/examples/rendering.md b/content/fa/docs/examples/rendering.md index a9fa75b5f..f88ef732c 100644 --- a/content/fa/docs/examples/rendering.md +++ b/content/fa/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H is a shortcut for map[string]interface{} - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // The specific definition of protobuf is written in the testdata/protoexample file. @@ -49,6 +49,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/secure-json.md b/content/fa/docs/examples/secure-json.md index 9f5642167..5cbdbf210 100644 --- a/content/fa/docs/examples/secure-json.md +++ b/content/fa/docs/examples/secure-json.md @@ -7,12 +7,12 @@ Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to re ```go func main() { - r := gin.Default() + router := gin.Default() // You can also use your own secure json prefix - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // Will output : while(1);["lena","austin","foo"] @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/support-lets-encrypt.md b/content/fa/docs/examples/support-lets-encrypt.md index c66288e87..82044829c 100644 --- a/content/fa/docs/examples/support-lets-encrypt.md +++ b/content/fa/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/fa/docs/examples/using-basicauth-middleware.md b/content/fa/docs/examples/using-basicauth-middleware.md index 318aca232..b3bc885ca 100644 --- a/content/fa/docs/examples/using-basicauth-middleware.md +++ b/content/fa/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // Group using gin.BasicAuth() middleware // gin.Accounts is a shortcut for map[string]string - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/examples/using-middleware.md b/content/fa/docs/examples/using-middleware.md index 2a3159cc3..92c23d828 100644 --- a/content/fa/docs/examples/using-middleware.md +++ b/content/fa/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // Global middleware // Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release. // By default gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery middleware recovers from any panics and writes a 500 if there was one. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // Per route middleware, you can add as many as you desire. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // Authorization group - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // exactly the same as: - authorized := r.Group("/") + authorized := router.Group("/") // per group middleware! in this case we use the custom created // AuthRequired() middleware just in the "authorized" group. authorized.Use(AuthRequired()) @@ -37,7 +37,7 @@ func main() { } // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/fa/docs/quickstart/_index.md b/content/fa/docs/quickstart/_index.md index f3f411fe0..3d2364987 100644 --- a/content/fa/docs/quickstart/_index.md +++ b/content/fa/docs/quickstart/_index.md @@ -69,13 +69,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // listen and serve on 0.0.0.0:8080 + router.Run() // listen and serve on 0.0.0.0:8080 } ``` diff --git a/content/fa/docs/testing/_index.md b/content/fa/docs/testing/_index.md index 766982b44..0685bb7bc 100644 --- a/content/fa/docs/testing/_index.md +++ b/content/fa/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/ascii-json.md b/content/ja/docs/examples/ascii-json.md index 5c8a75979..dbef91791 100644 --- a/content/ja/docs/examples/ascii-json.md +++ b/content/ja/docs/examples/ascii-json.md @@ -8,9 +8,9 @@ ASCII 文字列のみの JSON を出力できます。 ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -21,6 +21,6 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/bind-form-data-request-with-custom-struct.md b/content/ja/docs/examples/bind-form-data-request-with-custom-struct.md index 34d83fb5b..0f7f0a8b0 100644 --- a/content/ja/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/ja/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/ja/docs/examples/bind-single-binary-with-template.md b/content/ja/docs/examples/bind-single-binary-with-template.md index 07ebfa937..955be3f30 100644 --- a/content/ja/docs/examples/bind-single-binary-with-template.md +++ b/content/ja/docs/examples/bind-single-binary-with-template.md @@ -15,12 +15,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate は go-assets-builder によって埋め込まれたテンプレートたちをロードします。 diff --git a/content/ja/docs/examples/custom-middleware.md b/content/ja/docs/examples/custom-middleware.md index aa5d7ec99..d6ec472ef 100644 --- a/content/ja/docs/examples/custom-middleware.md +++ b/content/ja/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // "12345" が表示される @@ -37,7 +37,7 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/define-format-for-the-log-of-routes.md b/content/ja/docs/examples/define-format-for-the-log-of-routes.md index 172441891..8d603ca79 100644 --- a/content/ja/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/ja/docs/examples/define-format-for-the-log-of-routes.md @@ -22,24 +22,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // http://0.0.0.0:8080 でサーバーを立てる - r.Run() + router.Run() } ``` diff --git a/content/ja/docs/examples/goroutines-inside-a-middleware.md b/content/ja/docs/examples/goroutines-inside-a-middleware.md index 8123cadc0..7929223ad 100644 --- a/content/ja/docs/examples/goroutines-inside-a-middleware.md +++ b/content/ja/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // goroutine 内で使用するコピーを生成します cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // time.Sleep() を使って、長時間かかる処理をシミュレートします。5秒です。 time.Sleep(5 * time.Second) @@ -30,7 +30,7 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/html-rendering.md b/content/ja/docs/examples/html-rendering.md index 6fb9576c0..612146e0d 100644 --- a/content/ja/docs/examples/html-rendering.md +++ b/content/ja/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { 独自のデリミタを使用することもできます。 ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### カスタムテンプレート関数 diff --git a/content/ja/docs/examples/http2-server-push.md b/content/ja/docs/examples/http2-server-push.md index fb3f7e2c7..59aa5f63a 100644 --- a/content/ja/docs/examples/http2-server-push.md +++ b/content/ja/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // サーバープッシュするために pusher.Push() を使う if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // https://127.0.0.1:8080 でサーバーを立てる - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/ja/docs/examples/jsonp.md b/content/ja/docs/examples/jsonp.md index dae73ed0e..18d543efa 100644 --- a/content/ja/docs/examples/jsonp.md +++ b/content/ja/docs/examples/jsonp.md @@ -7,9 +7,9 @@ JSONP を使うことで、別のドメインのサーバーからレスポン ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,7 +20,7 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/pure-json.md b/content/ja/docs/examples/pure-json.md index 2cc0d7adf..f004b8884 100644 --- a/content/ja/docs/examples/pure-json.md +++ b/content/ja/docs/examples/pure-json.md @@ -9,24 +9,24 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // Unicode を返します - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // そのままの文字を返します - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/redirects.md b/content/ja/docs/examples/redirects.md index f4617c4ad..13979f423 100644 --- a/content/ja/docs/examples/redirects.md +++ b/content/ja/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false HTTP リダイレクトするのは簡単です。内部パス、外部URL両方のリダイレクトに対応しています。 ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { POSTからのHTTPリダイレクトのissueは [#444](https://github.com/gin-gonic/gin/issues/444) を参照してください。 ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Router でリダイレクトするには、下記のように `HandleContext` メソッドを使ってください。 ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/ja/docs/examples/rendering.md b/content/ja/docs/examples/rendering.md index b44dfbcdb..fc56e6c04 100644 --- a/content/ja/docs/examples/rendering.md +++ b/content/ja/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H は map[string]interface{} へのショートカットです。 - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // 構造体を使うこともできます。 var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // protobuf の定義は testdata/protoexample にかかれています。 @@ -49,7 +49,7 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/secure-json.md b/content/ja/docs/examples/secure-json.md index 3669a52f3..9adfcb743 100644 --- a/content/ja/docs/examples/secure-json.md +++ b/content/ja/docs/examples/secure-json.md @@ -8,12 +8,12 @@ SecureJSON メソッドを使うことで、JSON ハイジャックを防げま ```go func main() { - r := gin.Default() + router := gin.Default() // 別の prefix を使うこともできます - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // while(1);["lena","austin","foo"] が出力されます。 @@ -21,7 +21,7 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/support-lets-encrypt.md b/content/ja/docs/examples/support-lets-encrypt.md index a5a5dfadc..be625354f 100644 --- a/content/ja/docs/examples/support-lets-encrypt.md +++ b/content/ja/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/ja/docs/examples/using-basicauth-middleware.md b/content/ja/docs/examples/using-basicauth-middleware.md index db0c110e4..c9e02f562 100644 --- a/content/ja/docs/examples/using-basicauth-middleware.md +++ b/content/ja/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // gin.BasicAuth() ミドルウェアを使用したグループ // gin.Accounts は map[string]string へのショートカットです。 - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -35,7 +35,7 @@ func main() { }) // 0.0.0.0:8080 でサーバーを立てます。 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/examples/using-middleware.md b/content/ja/docs/examples/using-middleware.md index f43ca6b08..b8b2db961 100644 --- a/content/ja/docs/examples/using-middleware.md +++ b/content/ja/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // グローバルなミドルウェア // Logger ミドルウェアは GIN_MODE=release を設定してても、 gin.DefaultWriter にログを出力する // gin.DefaultWriter はデフォルトでは os.Stdout。 - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery ミドルウェアは panic が発生しても 500 エラーを返してくれる - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // 個別のルーティングに、ミドルウェアを好きに追加することもできる - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // 認証が必要なグループ - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // 下記と同一 - authorized := r.Group("/") + authorized := router.Group("/") // 個別のグループのミドルウェア。この例では、AuthRequired() ミドルウェアを認証が必要なグループに設定している。 authorized.Use(AuthRequired()) { @@ -36,7 +36,7 @@ func main() { } // 0.0.0.0:8080 でサーバーを立てる - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ja/docs/quickstart/_index.md b/content/ja/docs/quickstart/_index.md index 505733b47..f103a0d9e 100644 --- a/content/ja/docs/quickstart/_index.md +++ b/content/ja/docs/quickstart/_index.md @@ -68,13 +68,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // 0.0.0.0:8080 でサーバーを立てます。 + router.Run() // 0.0.0.0:8080 でサーバーを立てます。 } ``` diff --git a/content/ja/docs/testing/_index.md b/content/ja/docs/testing/_index.md index f88ce81a4..855499bab 100644 --- a/content/ja/docs/testing/_index.md +++ b/content/ja/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/ascii-json.md b/content/ko-kr/docs/examples/ascii-json.md index 8db492d85..ddd417e91 100644 --- a/content/ko-kr/docs/examples/ascii-json.md +++ b/content/ko-kr/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/bind-form-data-request-with-custom-struct.md b/content/ko-kr/docs/examples/bind-form-data-request-with-custom-struct.md index 5dd47cd31..9c08f5bdd 100644 --- a/content/ko-kr/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/ko-kr/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/ko-kr/docs/examples/bind-single-binary-with-template.md b/content/ko-kr/docs/examples/bind-single-binary-with-template.md index 99c109e99..5b7232acc 100644 --- a/content/ko-kr/docs/examples/bind-single-binary-with-template.md +++ b/content/ko-kr/docs/examples/bind-single-binary-with-template.md @@ -13,12 +13,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate은 go-assets-builder에 의해 임베디드 된 템플릿을 로드합니다 diff --git a/content/ko-kr/docs/examples/custom-middleware.md b/content/ko-kr/docs/examples/custom-middleware.md index 9c2afe1ea..a2f90d8b9 100644 --- a/content/ko-kr/docs/examples/custom-middleware.md +++ b/content/ko-kr/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // 출력내용: "12345" @@ -37,7 +37,7 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/define-format-for-the-log-of-routes.md b/content/ko-kr/docs/examples/define-format-for-the-log-of-routes.md index 1210c602e..2a5434983 100644 --- a/content/ko-kr/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/ko-kr/docs/examples/define-format-for-the-log-of-routes.md @@ -21,24 +21,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // 서버가 실행 되고 http://0.0.0.0:8080 에서 요청을 기다립니다. - r.Run() + router.Run() } ``` diff --git a/content/ko-kr/docs/examples/goroutines-inside-a-middleware.md b/content/ko-kr/docs/examples/goroutines-inside-a-middleware.md index d5277d4e3..c38553df7 100644 --- a/content/ko-kr/docs/examples/goroutines-inside-a-middleware.md +++ b/content/ko-kr/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // Go루틴 내부에서 사용하기 위한 복사본을 작성합니다. cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // time.Sleep()를 사용하여 장시간(5초) 작업을 시뮬레이션 합니다. time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/html-rendering.md b/content/ko-kr/docs/examples/html-rendering.md index 858da069b..0e6b73320 100644 --- a/content/ko-kr/docs/examples/html-rendering.md +++ b/content/ko-kr/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { 구분자를 사용자 정의하여 사용할 수도 있습니다. ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### 커스텀 템플릿 기능 diff --git a/content/ko-kr/docs/examples/http2-server-push.md b/content/ko-kr/docs/examples/http2-server-push.md index ec44bfba8..1091a197a 100644 --- a/content/ko-kr/docs/examples/http2-server-push.md +++ b/content/ko-kr/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // 서버 푸시를 위해 pusher.Push()를 사용합니다 if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // 서버가 실행 되고 https://127.0.0.1:8080 에서 요청을 기다립니다. - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/ko-kr/docs/examples/jsonp.md b/content/ko-kr/docs/examples/jsonp.md index dfc434acc..d05cf762b 100644 --- a/content/ko-kr/docs/examples/jsonp.md +++ b/content/ko-kr/docs/examples/jsonp.md @@ -7,9 +7,9 @@ JSONP를 사용하여 다른 도메인의 서버에 요청하고 데이터를 ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/pure-json.md b/content/ko-kr/docs/examples/pure-json.md index c79d58e67..98157ab73 100644 --- a/content/ko-kr/docs/examples/pure-json.md +++ b/content/ko-kr/docs/examples/pure-json.md @@ -9,23 +9,23 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // 유니코드 엔티티 반환 - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // 리터럴 문자 반환 - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/redirects.md b/content/ko-kr/docs/examples/redirects.md index 7953fb2fd..caf6ad883 100644 --- a/content/ko-kr/docs/examples/redirects.md +++ b/content/ko-kr/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false HTTP 리다이렉트 하는 것은 간단합니다. 내부와 외부위치를 모두 지원합니다. ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { 라우터 리다이렉트를 실행하려면, 아래와 같이 `HandleContext`를 사용하세요. ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/ko-kr/docs/examples/rendering.md b/content/ko-kr/docs/examples/rendering.md index 01ed56122..fef233df6 100644 --- a/content/ko-kr/docs/examples/rendering.md +++ b/content/ko-kr/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H은 map[string]interface{} 타입입니다. - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // 구조체도 사용할 수 있습니다. var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // protobuf의 정의는 testdata/protoexample 파일에 작성되어 있습니다. @@ -49,6 +49,6 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/secure-json.md b/content/ko-kr/docs/examples/secure-json.md index d5ab5e628..32ee67765 100644 --- a/content/ko-kr/docs/examples/secure-json.md +++ b/content/ko-kr/docs/examples/secure-json.md @@ -8,12 +8,12 @@ json 하이재킹을 방지하기 위해 SecureJSON를 사용합니다. ```go func main() { - r := gin.Default() + router := gin.Default() // 자체적인 보안 json 접두사를 사용할 수도 있습니다. - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // 출력내용 : while(1);["lena","austin","foo"] @@ -21,6 +21,6 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/support-lets-encrypt.md b/content/ko-kr/docs/examples/support-lets-encrypt.md index 504f527ac..66d481505 100644 --- a/content/ko-kr/docs/examples/support-lets-encrypt.md +++ b/content/ko-kr/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/ko-kr/docs/examples/using-basicauth-middleware.md b/content/ko-kr/docs/examples/using-basicauth-middleware.md index 934a7f769..9e696d654 100644 --- a/content/ko-kr/docs/examples/using-basicauth-middleware.md +++ b/content/ko-kr/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // gin.BasicAuth() 미들웨어를 사용하여 그룹화 하기 // gin.Accounts는 map[string]string 타입입니다. - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/examples/using-middleware.md b/content/ko-kr/docs/examples/using-middleware.md index ee033e2c2..884960d6e 100644 --- a/content/ko-kr/docs/examples/using-middleware.md +++ b/content/ko-kr/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // Global middleware // GIN_MODE=release로 하더라도 Logger 미들웨어는 gin.DefaultWriter에 로그를 기록합니다. // 기본값 gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery 미들웨어는 panic이 발생하면 500 에러를 씁니다. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // 각 라우트 당 원하는만큼 미들웨어를 추가 할 수 있습니다. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // 권한 그룹 - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // 다음과 동일합니다: - authorized := r.Group("/") + authorized := router.Group("/") // 그룹별로 미들웨어를 사용할 수 있습니다! // 이 경우 "authorized"그룹에서만 사용자 정의 생성된 AuthRequired() 미들웨어를 사용합니다. authorized.Use(AuthRequired()) @@ -37,7 +37,7 @@ func main() { } // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/ko-kr/docs/quickstart/_index.md b/content/ko-kr/docs/quickstart/_index.md index 3fe43137b..83edc7c2e 100644 --- a/content/ko-kr/docs/quickstart/_index.md +++ b/content/ko-kr/docs/quickstart/_index.md @@ -83,13 +83,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. + router.Run() // 서버가 실행 되고 0.0.0.0:8080 에서 요청을 기다립니다. } ``` diff --git a/content/ko-kr/docs/testing/_index.md b/content/ko-kr/docs/testing/_index.md index 3771fee31..8ef14e4df 100644 --- a/content/ko-kr/docs/testing/_index.md +++ b/content/ko-kr/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/ascii-json.md b/content/pt/docs/examples/ascii-json.md index 6c531ff92..1a9efbf4c 100644 --- a/content/pt/docs/examples/ascii-json.md +++ b/content/pt/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ Usando a `AsciiJSON` para gerar JSON de apenas ASCII com caracteres que não sã ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // Ouvir e servir na 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/bind-form-data-request-with-custom-struct.md b/content/pt/docs/examples/bind-form-data-request-with-custom-struct.md index 6e56a42c5..abf68ab48 100644 --- a/content/pt/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/pt/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/pt/docs/examples/bind-single-binary-with-template.md b/content/pt/docs/examples/bind-single-binary-with-template.md index 28cda90d2..2b895d3b7 100644 --- a/content/pt/docs/examples/bind-single-binary-with-template.md +++ b/content/pt/docs/examples/bind-single-binary-with-template.md @@ -14,12 +14,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate carrega os modelos de marcação fixado pelo go-assets-builder diff --git a/content/pt/docs/examples/custom-middleware.md b/content/pt/docs/examples/custom-middleware.md index 9f8adede5..6027bb2c6 100644 --- a/content/pt/docs/examples/custom-middleware.md +++ b/content/pt/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // imprimiria: "12345" @@ -37,7 +37,7 @@ func main() { }) // Ouvir e servir na 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/define-format-for-the-log-of-routes.md b/content/pt/docs/examples/define-format-for-the-log-of-routes.md index 03bcc56ea..4abf6e9c5 100644 --- a/content/pt/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/pt/docs/examples/define-format-for-the-log-of-routes.md @@ -23,24 +23,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // Ouvir e servir na http://0.0.0.0:8080 - r.Run() + router.Run() } ``` diff --git a/content/pt/docs/examples/goroutines-inside-a-middleware.md b/content/pt/docs/examples/goroutines-inside-a-middleware.md index 0b5c16c46..1b9f6414f 100644 --- a/content/pt/docs/examples/goroutines-inside-a-middleware.md +++ b/content/pt/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ Quando começares novas rotinas de Go dentro dum intermediário ou manipulador, ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // criar cópia a ser usada dentro da rotina de go cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // simular uma tarefa longa com time.Sleep(). 5 segundos time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // ouvir e servir na porta 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/html-rendering.md b/content/pt/docs/examples/html-rendering.md index 98d309d02..f95cb9346 100644 --- a/content/pt/docs/examples/html-rendering.md +++ b/content/pt/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { Tu podes usar delimitadores personalizados: ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### Funções de Modelo de Marcação Personalizado diff --git a/content/pt/docs/examples/http2-server-push.md b/content/pt/docs/examples/http2-server-push.md index c0d038685..6110cd548 100644 --- a/content/pt/docs/examples/http2-server-push.md +++ b/content/pt/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // usar pusher.Push() para impulsionar o servidor. if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // ouvir e servir no https://127.0.0.1:8080 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/pt/docs/examples/jsonp.md b/content/pt/docs/examples/jsonp.md index 07a3dc4db..a75e0ec88 100644 --- a/content/pt/docs/examples/jsonp.md +++ b/content/pt/docs/examples/jsonp.md @@ -7,9 +7,9 @@ Usando JSONP para pedir dados dum servidor num domínio diferente. Adicione a fu ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // ouvir e servir no 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/pure-json.md b/content/pt/docs/examples/pure-json.md index 52ec5b46a..b0b426a26 100644 --- a/content/pt/docs/examples/pure-json.md +++ b/content/pt/docs/examples/pure-json.md @@ -7,23 +7,23 @@ Normalmente, a JSON substitui os caracteres de HTML especiais com suas entidades ```go func main() { - r := gin.Default() + router := gin.Default() // servir as entidades de unicode - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // servir os caracteres literais - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // ouvir e servir no 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/redirects.md b/content/pt/docs/examples/redirects.md index 5212c4000..14ed099ed 100644 --- a/content/pt/docs/examples/redirects.md +++ b/content/pt/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false Emitir um redirecionamento de HTTP é fácil. Ambas localizações internas e externas são suportadas: ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Emitir um redirecionamento de HTTP a partir do `POST`. Consulte o problema: [#444](https://github.com/gin-gonic/gin/issues/444): ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Emitir um redirecionamento de roteador, use `HandleContext` como abaixo: ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/pt/docs/examples/rendering.md b/content/pt/docs/examples/rendering.md index d5ca12bd1..3c1e67247 100644 --- a/content/pt/docs/examples/rendering.md +++ b/content/pt/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // "gin.H" é um atalho para "map[string]interface{}" - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // também podes usar uma estrutura var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // a definição específica do protobuf @@ -50,6 +50,6 @@ func main() { }) // ouvir e servir na 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/secure-json.md b/content/pt/docs/examples/secure-json.md index 7a4cc3372..e7926f7ab 100644 --- a/content/pt/docs/examples/secure-json.md +++ b/content/pt/docs/examples/secure-json.md @@ -7,12 +7,12 @@ Usando SecureJSON para impedir o sequestro do JSON. Por padrão adiciona `"while ```go func main() { - r := gin.Default() + router := gin.Default() // podes também usar o teu próprio prefixo de JSON seguro - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // resultará em: while(1);["lena","austin","foo"] @@ -20,6 +20,6 @@ func main() { }) // ouvir e servir no 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/support-lets-encrypt.md b/content/pt/docs/examples/support-lets-encrypt.md index 63209f021..746f6171c 100644 --- a/content/pt/docs/examples/support-lets-encrypt.md +++ b/content/pt/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // manipulador de ping - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // manipulador de ping - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/pt/docs/examples/using-basicauth-middleware.md b/content/pt/docs/examples/using-basicauth-middleware.md index 13ffc5602..605ad7b51 100644 --- a/content/pt/docs/examples/using-basicauth-middleware.md +++ b/content/pt/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // grupo usando intermediário de "gin.BasicAuth()" // "gin.Accounts" é um atalho para "map[string]string" - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // ouvir e servir no 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/examples/using-middleware.md b/content/pt/docs/examples/using-middleware.md index db9a819d9..d4e464e96 100644 --- a/content/pt/docs/examples/using-middleware.md +++ b/content/pt/docs/examples/using-middleware.md @@ -12,19 +12,19 @@ func main() { // intermediário registador escreverá os registos ao "gin.DefaultWriter", // mesmo se definires com "GIN_MODE=release". // por padrão "gin.DefaultWriter = os.Stdout" - r.Use(gin.Logger()) + router.Use(gin.Logger()) // intermediário de recuperação recupera de quaisquer pânicos e // escreve um 500 se ouve um. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // intermediário por rota, podes adicionar tanto quanto desejares. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // grupo de autorização - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // exatamente o mesmo que: - authorized := r.Group("/") + authorized := router.Group("/") // intermediário por grupo! neste caso usamos o intermediário // "AuthRequired()" criado de maneira personalizada só no // grupo "authorized". @@ -40,7 +40,7 @@ func main() { } // ouvir e servir no 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/pt/docs/quickstart/_index.md b/content/pt/docs/quickstart/_index.md index dcf21f27d..8326edd3c 100644 --- a/content/pt/docs/quickstart/_index.md +++ b/content/pt/docs/quickstart/_index.md @@ -69,13 +69,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // oiça e sirva na `0.0.0.0:8080` + router.Run() // oiça e sirva na `0.0.0.0:8080` } ``` diff --git a/content/pt/docs/testing/_index.md b/content/pt/docs/testing/_index.md index 645d71baf..1fc074ea2 100644 --- a/content/pt/docs/testing/_index.md +++ b/content/pt/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/ascii-json.md b/content/tr/docs/examples/ascii-json.md index 82ab48d2a..d8e62319f 100644 --- a/content/tr/docs/examples/ascii-json.md +++ b/content/tr/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ Using AsciiJSON to Generates ASCII-only JSON with escaped non-ASCII characters. ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/bind-form-data-request-with-custom-struct.md b/content/tr/docs/examples/bind-form-data-request-with-custom-struct.md index 2882e8656..7286ea4f9 100644 --- a/content/tr/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/tr/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/tr/docs/examples/bind-single-binary-with-template.md b/content/tr/docs/examples/bind-single-binary-with-template.md index 36f0bb212..eab489293 100644 --- a/content/tr/docs/examples/bind-single-binary-with-template.md +++ b/content/tr/docs/examples/bind-single-binary-with-template.md @@ -14,12 +14,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate loads templates embedded by go-assets-builder diff --git a/content/tr/docs/examples/custom-middleware.md b/content/tr/docs/examples/custom-middleware.md index dd7407b07..3e87bf2f0 100644 --- a/content/tr/docs/examples/custom-middleware.md +++ b/content/tr/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // it would print: "12345" @@ -37,7 +37,7 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/define-format-for-the-log-of-routes.md b/content/tr/docs/examples/define-format-for-the-log-of-routes.md index 6cfdaa68f..7d101aa89 100644 --- a/content/tr/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/tr/docs/examples/define-format-for-the-log-of-routes.md @@ -21,24 +21,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // Listen and Server in http://0.0.0.0:8080 - r.Run() + router.Run() } ``` diff --git a/content/tr/docs/examples/goroutines-inside-a-middleware.md b/content/tr/docs/examples/goroutines-inside-a-middleware.md index 122593a1b..1461c9626 100644 --- a/content/tr/docs/examples/goroutines-inside-a-middleware.md +++ b/content/tr/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // create copy to be used inside the goroutine cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // simulate a long task with time.Sleep(). 5 seconds time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/html-rendering.md b/content/tr/docs/examples/html-rendering.md index cfa8e825a..388f08560 100644 --- a/content/tr/docs/examples/html-rendering.md +++ b/content/tr/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { You may use custom delims ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` ### Custom Template Funcs diff --git a/content/tr/docs/examples/http2-server-push.md b/content/tr/docs/examples/http2-server-push.md index 00bbd12d8..51e0440e8 100644 --- a/content/tr/docs/examples/http2-server-push.md +++ b/content/tr/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // use pusher.Push() to do server push if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // Listen and Server in https://127.0.0.1:8080 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/tr/docs/examples/jsonp.md b/content/tr/docs/examples/jsonp.md index 63c7dc551..e88fb3146 100644 --- a/content/tr/docs/examples/jsonp.md +++ b/content/tr/docs/examples/jsonp.md @@ -7,9 +7,9 @@ Using JSONP to request data from a server in a different domain. Add callback t ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/pure-json.md b/content/tr/docs/examples/pure-json.md index d91f905ef..e5205fe40 100644 --- a/content/tr/docs/examples/pure-json.md +++ b/content/tr/docs/examples/pure-json.md @@ -8,23 +8,23 @@ This feature is unavailable in Go 1.6 and lower. ```go func main() { - r := gin.Default() + router := gin.Default() // Serves unicode entities - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // Serves literal characters - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/redirects.md b/content/tr/docs/examples/redirects.md index f7d823eca..b32e96563 100644 --- a/content/tr/docs/examples/redirects.md +++ b/content/tr/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false Issuing a HTTP redirect is easy. Both internal and external locations are supported. ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Issuing a Router redirect, use `HandleContext` like below. ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/tr/docs/examples/rendering.md b/content/tr/docs/examples/rendering.md index a9fa75b5f..f88ef732c 100644 --- a/content/tr/docs/examples/rendering.md +++ b/content/tr/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H is a shortcut for map[string]interface{} - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // The specific definition of protobuf is written in the testdata/protoexample file. @@ -49,6 +49,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/secure-json.md b/content/tr/docs/examples/secure-json.md index 9f5642167..5cbdbf210 100644 --- a/content/tr/docs/examples/secure-json.md +++ b/content/tr/docs/examples/secure-json.md @@ -7,12 +7,12 @@ Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to re ```go func main() { - r := gin.Default() + router := gin.Default() // You can also use your own secure json prefix - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // Will output : while(1);["lena","austin","foo"] @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/support-lets-encrypt.md b/content/tr/docs/examples/support-lets-encrypt.md index c66288e87..82044829c 100644 --- a/content/tr/docs/examples/support-lets-encrypt.md +++ b/content/tr/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/tr/docs/examples/using-basicauth-middleware.md b/content/tr/docs/examples/using-basicauth-middleware.md index 318aca232..b3bc885ca 100644 --- a/content/tr/docs/examples/using-basicauth-middleware.md +++ b/content/tr/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // Group using gin.BasicAuth() middleware // gin.Accounts is a shortcut for map[string]string - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/examples/using-middleware.md b/content/tr/docs/examples/using-middleware.md index 2a3159cc3..92c23d828 100644 --- a/content/tr/docs/examples/using-middleware.md +++ b/content/tr/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // Global middleware // Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release. // By default gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery middleware recovers from any panics and writes a 500 if there was one. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // Per route middleware, you can add as many as you desire. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // Authorization group - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // exactly the same as: - authorized := r.Group("/") + authorized := router.Group("/") // per group middleware! in this case we use the custom created // AuthRequired() middleware just in the "authorized" group. authorized.Use(AuthRequired()) @@ -37,7 +37,7 @@ func main() { } // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/tr/docs/quickstart/_index.md b/content/tr/docs/quickstart/_index.md index 0c72603e2..c97d80a47 100644 --- a/content/tr/docs/quickstart/_index.md +++ b/content/tr/docs/quickstart/_index.md @@ -68,13 +68,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // 0.0.0.0:8080 adresini dinleyin ve servis edin + router.Run() // 0.0.0.0:8080 adresini dinleyin ve servis edin } ``` diff --git a/content/tr/docs/testing/_index.md b/content/tr/docs/testing/_index.md index fcb04a896..f8166745d 100644 --- a/content/tr/docs/testing/_index.md +++ b/content/tr/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/ascii-json.md b/content/zh-cn/docs/examples/ascii-json.md index cf4f4ee27..9ca8fc94b 100644 --- a/content/zh-cn/docs/examples/ascii-json.md +++ b/content/zh-cn/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/bind-form-data-request-with-custom-struct.md b/content/zh-cn/docs/examples/bind-form-data-request-with-custom-struct.md index cc69d2ccd..2fba3bc64 100644 --- a/content/zh-cn/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/zh-cn/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/zh-cn/docs/examples/bind-single-binary-with-template.md b/content/zh-cn/docs/examples/bind-single-binary-with-template.md index ebcce3e94..0895551f8 100644 --- a/content/zh-cn/docs/examples/bind-single-binary-with-template.md +++ b/content/zh-cn/docs/examples/bind-single-binary-with-template.md @@ -13,12 +13,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate 加载由 go-assets-builder 嵌入的模板 diff --git a/content/zh-cn/docs/examples/custom-middleware.md b/content/zh-cn/docs/examples/custom-middleware.md index 608be9498..adb6fe6c0 100644 --- a/content/zh-cn/docs/examples/custom-middleware.md +++ b/content/zh-cn/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // 打印:"12345" @@ -37,7 +37,7 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/define-format-for-the-log-of-routes.md b/content/zh-cn/docs/examples/define-format-for-the-log-of-routes.md index 9112801fe..e4714dc91 100644 --- a/content/zh-cn/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/zh-cn/docs/examples/define-format-for-the-log-of-routes.md @@ -21,24 +21,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run() + router.Run() } ``` diff --git a/content/zh-cn/docs/examples/goroutines-inside-a-middleware.md b/content/zh-cn/docs/examples/goroutines-inside-a-middleware.md index f5d367be8..12320d52d 100644 --- a/content/zh-cn/docs/examples/goroutines-inside-a-middleware.md +++ b/content/zh-cn/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // 创建在 goroutine 中使用的副本 cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // 用 time.Sleep() 模拟一个长任务。 time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/html-rendering.md b/content/zh-cn/docs/examples/html-rendering.md index a648697c5..94716c2aa 100644 --- a/content/zh-cn/docs/examples/html-rendering.md +++ b/content/zh-cn/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { 你可以使用自定义分隔 ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` #### 自定义模板功能 diff --git a/content/zh-cn/docs/examples/http2-server-push.md b/content/zh-cn/docs/examples/http2-server-push.md index bd24d4478..036489cff 100644 --- a/content/zh-cn/docs/examples/http2-server-push.md +++ b/content/zh-cn/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // 使用 pusher.Push() 做服务器推送 if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // 监听并在 https://127.0.0.1:8080 上启动服务 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/zh-cn/docs/examples/jsonp.md b/content/zh-cn/docs/examples/jsonp.md index e418dc218..40d9c78ab 100644 --- a/content/zh-cn/docs/examples/jsonp.md +++ b/content/zh-cn/docs/examples/jsonp.md @@ -7,9 +7,9 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP", func(c *gin.Context) { + router.GET("/JSONP", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/pure-json.md b/content/zh-cn/docs/examples/pure-json.md index c634f70d7..978d4002c 100644 --- a/content/zh-cn/docs/examples/pure-json.md +++ b/content/zh-cn/docs/examples/pure-json.md @@ -7,23 +7,23 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // 提供 unicode 实体 - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // 提供字面字符 - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/redirects.md b/content/zh-cn/docs/examples/redirects.md index 5f6c243f7..a44060b76 100644 --- a/content/zh-cn/docs/examples/redirects.md +++ b/content/zh-cn/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false HTTP 重定向很容易。 内部、外部重定向均支持。 ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { 通过 POST 方法进行 HTTP 重定向。请参考 issue:[#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { 路由重定向,使用 `HandleContext`: ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/zh-cn/docs/examples/rendering.md b/content/zh-cn/docs/examples/rendering.md index 83e49f39e..444f5c2a9 100644 --- a/content/zh-cn/docs/examples/rendering.md +++ b/content/zh-cn/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H 是 map[string]interface{} 的一种快捷方式 - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // 你也可以使用一个结构体 var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // protobuf 的具体定义写在 testdata/protoexample 文件中。 @@ -49,6 +49,6 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/secure-json.md b/content/zh-cn/docs/examples/secure-json.md index a85559976..0f26affbf 100644 --- a/content/zh-cn/docs/examples/secure-json.md +++ b/content/zh-cn/docs/examples/secure-json.md @@ -7,12 +7,12 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // 你也可以使用自己的 SecureJSON 前缀 - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // 将输出:while(1);["lena","austin","foo"] @@ -20,6 +20,6 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/support-lets-encrypt.md b/content/zh-cn/docs/examples/support-lets-encrypt.md index 54707824a..a36656234 100644 --- a/content/zh-cn/docs/examples/support-lets-encrypt.md +++ b/content/zh-cn/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/zh-cn/docs/examples/using-basicauth-middleware.md b/content/zh-cn/docs/examples/using-basicauth-middleware.md index e0aad8033..b0564857f 100644 --- a/content/zh-cn/docs/examples/using-basicauth-middleware.md +++ b/content/zh-cn/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // 路由组使用 gin.BasicAuth() 中间件 // gin.Accounts 是 map[string]string 的一种快捷方式 - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/examples/using-middleware.md b/content/zh-cn/docs/examples/using-middleware.md index 3d2ab1b47..6fbb17cf9 100644 --- a/content/zh-cn/docs/examples/using-middleware.md +++ b/content/zh-cn/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // 全局中间件 // Logger 中间件将日志写入 gin.DefaultWriter,即使你将 GIN_MODE 设置为 release。 // By default gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery 中间件会 recover 任何 panic。如果有 panic 的话,会写入 500。 - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // 你可以为每个路由添加任意数量的中间件。 - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // 认证路由组 - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // 和使用以下两行代码的效果完全一样: - authorized := r.Group("/") + authorized := router.Group("/") // 路由组中间件! 在此例中,我们在 "authorized" 路由组中使用自定义创建的 // AuthRequired() 中间件 authorized.Use(AuthRequired()) @@ -37,7 +37,7 @@ func main() { } // 监听并在 0.0.0.0:8080 上启动服务 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-cn/docs/quickstart/_index.md b/content/zh-cn/docs/quickstart/_index.md index ba76a0d02..7bc02bce5 100644 --- a/content/zh-cn/docs/quickstart/_index.md +++ b/content/zh-cn/docs/quickstart/_index.md @@ -66,13 +66,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // 监听并在 0.0.0.0:8080 上启动服务 + router.Run() // 监听并在 0.0.0.0:8080 上启动服务 } ``` diff --git a/content/zh-cn/docs/testing/_index.md b/content/zh-cn/docs/testing/_index.md index afa66e6aa..a796aaac2 100644 --- a/content/zh-cn/docs/testing/_index.md +++ b/content/zh-cn/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/ascii-json.md b/content/zh-tw/docs/examples/ascii-json.md index 82ab48d2a..d8e62319f 100644 --- a/content/zh-tw/docs/examples/ascii-json.md +++ b/content/zh-tw/docs/examples/ascii-json.md @@ -7,9 +7,9 @@ Using AsciiJSON to Generates ASCII-only JSON with escaped non-ASCII characters. ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { data := map[string]interface{}{ "lang": "GO语言", "tag": "
", @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/bind-form-data-request-with-custom-struct.md b/content/zh-tw/docs/examples/bind-form-data-request-with-custom-struct.md index a6a04815e..03d995d73 100644 --- a/content/zh-tw/docs/examples/bind-form-data-request-with-custom-struct.md +++ b/content/zh-tw/docs/examples/bind-form-data-request-with-custom-struct.md @@ -55,12 +55,12 @@ func GetDataD(c *gin.Context) { } func main() { - r := gin.Default() - r.GET("/getb", GetDataB) - r.GET("/getc", GetDataC) - r.GET("/getd", GetDataD) + router := gin.Default() + router.GET("/getb", GetDataB) + router.GET("/getc", GetDataC) + router.GET("/getd", GetDataD) - r.Run() + router.Run() } ``` diff --git a/content/zh-tw/docs/examples/bind-single-binary-with-template.md b/content/zh-tw/docs/examples/bind-single-binary-with-template.md index 018e05816..a2c096e7a 100644 --- a/content/zh-tw/docs/examples/bind-single-binary-with-template.md +++ b/content/zh-tw/docs/examples/bind-single-binary-with-template.md @@ -15,12 +15,12 @@ func main() { if err != nil { panic(err) } - r.SetHTMLTemplate(t) + router.SetHTMLTemplate(t) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "/html/index.tmpl", nil) }) - r.Run(":8080") + router.Run(":8080") } // loadTemplate loads templates embedded by go-assets-builder diff --git a/content/zh-tw/docs/examples/custom-middleware.md b/content/zh-tw/docs/examples/custom-middleware.md index dd7407b07..3e87bf2f0 100644 --- a/content/zh-tw/docs/examples/custom-middleware.md +++ b/content/zh-tw/docs/examples/custom-middleware.md @@ -27,9 +27,9 @@ func Logger() gin.HandlerFunc { func main() { r := gin.New() - r.Use(Logger()) + router.Use(Logger()) - r.GET("/test", func(c *gin.Context) { + router.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // it would print: "12345" @@ -37,7 +37,7 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/define-format-for-the-log-of-routes.md b/content/zh-tw/docs/examples/define-format-for-the-log-of-routes.md index 6cfdaa68f..7d101aa89 100644 --- a/content/zh-tw/docs/examples/define-format-for-the-log-of-routes.md +++ b/content/zh-tw/docs/examples/define-format-for-the-log-of-routes.md @@ -21,24 +21,24 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) { log.Printf("endpoint %v %v %v %v\n", httpMethod, absolutePath, handlerName, nuHandlers) } - r.POST("/foo", func(c *gin.Context) { + router.POST("/foo", func(c *gin.Context) { c.JSON(http.StatusOK, "foo") }) - r.GET("/bar", func(c *gin.Context) { + router.GET("/bar", func(c *gin.Context) { c.JSON(http.StatusOK, "bar") }) - r.GET("/status", func(c *gin.Context) { + router.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, "ok") }) // Listen and Server in http://0.0.0.0:8080 - r.Run() + router.Run() } ``` diff --git a/content/zh-tw/docs/examples/goroutines-inside-a-middleware.md b/content/zh-tw/docs/examples/goroutines-inside-a-middleware.md index 122593a1b..1461c9626 100644 --- a/content/zh-tw/docs/examples/goroutines-inside-a-middleware.md +++ b/content/zh-tw/docs/examples/goroutines-inside-a-middleware.md @@ -7,9 +7,9 @@ When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/long_async", func(c *gin.Context) { + router.GET("/long_async", func(c *gin.Context) { // create copy to be used inside the goroutine cCp := c.Copy() go func() { @@ -21,7 +21,7 @@ func main() { }() }) - r.GET("/long_sync", func(c *gin.Context) { + router.GET("/long_sync", func(c *gin.Context) { // simulate a long task with time.Sleep(). 5 seconds time.Sleep(5 * time.Second) @@ -30,6 +30,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/html-rendering.md b/content/zh-tw/docs/examples/html-rendering.md index df2e1450a..abfc56b6e 100644 --- a/content/zh-tw/docs/examples/html-rendering.md +++ b/content/zh-tw/docs/examples/html-rendering.md @@ -93,9 +93,9 @@ func main() { You may use custom delims ```go - r := gin.Default() - r.Delims("{[{", "}]}") - r.LoadHTMLGlob("/path/to/templates") + router := gin.Default() + router.Delims("{[{", "}]}") + router.LoadHTMLGlob("/path/to/templates") ``` #### Custom Template Funcs diff --git a/content/zh-tw/docs/examples/http2-server-push.md b/content/zh-tw/docs/examples/http2-server-push.md index 00bbd12d8..51e0440e8 100644 --- a/content/zh-tw/docs/examples/http2-server-push.md +++ b/content/zh-tw/docs/examples/http2-server-push.md @@ -28,11 +28,11 @@ var html = template.Must(template.New("https").Parse(` `)) func main() { - r := gin.Default() - r.Static("/assets", "./assets") - r.SetHTMLTemplate(html) + router := gin.Default() + router.Static("/assets", "./assets") + router.SetHTMLTemplate(html) - r.GET("/", func(c *gin.Context) { + router.GET("/", func(c *gin.Context) { if pusher := c.Writer.Pusher(); pusher != nil { // use pusher.Push() to do server push if err := pusher.Push("/assets/app.js", nil); err != nil { @@ -45,7 +45,7 @@ func main() { }) // Listen and Server in https://127.0.0.1:8080 - r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") + router.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key") } ``` diff --git a/content/zh-tw/docs/examples/jsonp.md b/content/zh-tw/docs/examples/jsonp.md index 63c7dc551..e88fb3146 100644 --- a/content/zh-tw/docs/examples/jsonp.md +++ b/content/zh-tw/docs/examples/jsonp.md @@ -7,9 +7,9 @@ Using JSONP to request data from a server in a different domain. Add callback t ```go func main() { - r := gin.Default() + router := gin.Default() - r.GET("/JSONP?callback=x", func(c *gin.Context) { + router.GET("/JSONP?callback=x", func(c *gin.Context) { data := map[string]interface{}{ "foo": "bar", } @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/pure-json.md b/content/zh-tw/docs/examples/pure-json.md index d91f905ef..e5205fe40 100644 --- a/content/zh-tw/docs/examples/pure-json.md +++ b/content/zh-tw/docs/examples/pure-json.md @@ -8,23 +8,23 @@ This feature is unavailable in Go 1.6 and lower. ```go func main() { - r := gin.Default() + router := gin.Default() // Serves unicode entities - r.GET("/json", func(c *gin.Context) { + router.GET("/json", func(c *gin.Context) { c.JSON(200, gin.H{ "html": "Hello, world!", }) }) // Serves literal characters - r.GET("/purejson", func(c *gin.Context) { + router.GET("/purejson", func(c *gin.Context) { c.PureJSON(200, gin.H{ "html": "Hello, world!", }) }) // listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/redirects.md b/content/zh-tw/docs/examples/redirects.md index f7d823eca..b32e96563 100644 --- a/content/zh-tw/docs/examples/redirects.md +++ b/content/zh-tw/docs/examples/redirects.md @@ -6,7 +6,7 @@ draft: false Issuing a HTTP redirect is easy. Both internal and external locations are supported. ```go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` @@ -14,7 +14,7 @@ r.GET("/test", func(c *gin.Context) { Issuing a HTTP redirect from POST. Refer to issue: [#444](https://github.com/gin-gonic/gin/issues/444) ```go -r.POST("/test", func(c *gin.Context) { +router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo") }) ``` @@ -22,11 +22,11 @@ r.POST("/test", func(c *gin.Context) { Issuing a Router redirect, use `HandleContext` like below. ``` go -r.GET("/test", func(c *gin.Context) { +router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" - r.HandleContext(c) + router.HandleContext(c) }) -r.GET("/test2", func(c *gin.Context) { +router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"}) }) ``` diff --git a/content/zh-tw/docs/examples/rendering.md b/content/zh-tw/docs/examples/rendering.md index a9fa75b5f..f88ef732c 100644 --- a/content/zh-tw/docs/examples/rendering.md +++ b/content/zh-tw/docs/examples/rendering.md @@ -5,14 +5,14 @@ draft: false ```go func main() { - r := gin.Default() + router := gin.Default() // gin.H is a shortcut for map[string]interface{} - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/moreJSON", func(c *gin.Context) { + router.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { Name string `json:"user"` @@ -27,15 +27,15 @@ func main() { c.JSON(http.StatusOK, msg) }) - r.GET("/someXML", func(c *gin.Context) { + router.GET("/someXML", func(c *gin.Context) { c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someYAML", func(c *gin.Context) { + router.GET("/someYAML", func(c *gin.Context) { c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) }) - r.GET("/someProtoBuf", func(c *gin.Context) { + router.GET("/someProtoBuf", func(c *gin.Context) { reps := []int64{int64(1), int64(2)} label := "test" // The specific definition of protobuf is written in the testdata/protoexample file. @@ -49,6 +49,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/secure-json.md b/content/zh-tw/docs/examples/secure-json.md index 9f5642167..5cbdbf210 100644 --- a/content/zh-tw/docs/examples/secure-json.md +++ b/content/zh-tw/docs/examples/secure-json.md @@ -7,12 +7,12 @@ Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to re ```go func main() { - r := gin.Default() + router := gin.Default() // You can also use your own secure json prefix - // r.SecureJsonPrefix(")]}',\n") + // router.SecureJsonPrefix(")]}',\n") - r.GET("/someJSON", func(c *gin.Context) { + router.GET("/someJSON", func(c *gin.Context) { names := []string{"lena", "austin", "foo"} // Will output : while(1);["lena","austin","foo"] @@ -20,6 +20,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/support-lets-encrypt.md b/content/zh-tw/docs/examples/support-lets-encrypt.md index c66288e87..82044829c 100644 --- a/content/zh-tw/docs/examples/support-lets-encrypt.md +++ b/content/zh-tw/docs/examples/support-lets-encrypt.md @@ -16,10 +16,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) @@ -41,10 +41,10 @@ import ( ) func main() { - r := gin.Default() + router := gin.Default() // Ping handler - r.GET("/ping", func(c *gin.Context) { + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) diff --git a/content/zh-tw/docs/examples/using-basicauth-middleware.md b/content/zh-tw/docs/examples/using-basicauth-middleware.md index 318aca232..b3bc885ca 100644 --- a/content/zh-tw/docs/examples/using-basicauth-middleware.md +++ b/content/zh-tw/docs/examples/using-basicauth-middleware.md @@ -12,11 +12,11 @@ var secrets = gin.H{ } func main() { - r := gin.Default() + router := gin.Default() // Group using gin.BasicAuth() middleware // gin.Accounts is a shortcut for map[string]string - authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{ + authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{ "foo": "bar", "austin": "1234", "lena": "hello2", @@ -36,6 +36,6 @@ func main() { }) // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/examples/using-middleware.md b/content/zh-tw/docs/examples/using-middleware.md index 2a3159cc3..92c23d828 100644 --- a/content/zh-tw/docs/examples/using-middleware.md +++ b/content/zh-tw/docs/examples/using-middleware.md @@ -11,18 +11,18 @@ func main() { // Global middleware // Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release. // By default gin.DefaultWriter = os.Stdout - r.Use(gin.Logger()) + router.Use(gin.Logger()) // Recovery middleware recovers from any panics and writes a 500 if there was one. - r.Use(gin.Recovery()) + router.Use(gin.Recovery()) // Per route middleware, you can add as many as you desire. - r.GET("/benchmark", MyBenchLogger(), benchEndpoint) + router.GET("/benchmark", MyBenchLogger(), benchEndpoint) // Authorization group - // authorized := r.Group("/", AuthRequired()) + // authorized := router.Group("/", AuthRequired()) // exactly the same as: - authorized := r.Group("/") + authorized := router.Group("/") // per group middleware! in this case we use the custom created // AuthRequired() middleware just in the "authorized" group. authorized.Use(AuthRequired()) @@ -37,7 +37,7 @@ func main() { } // Listen and serve on 0.0.0.0:8080 - r.Run(":8080") + router.Run(":8080") } ``` diff --git a/content/zh-tw/docs/quickstart/_index.md b/content/zh-tw/docs/quickstart/_index.md index d3df6ea73..a10f6f6f9 100644 --- a/content/zh-tw/docs/quickstart/_index.md +++ b/content/zh-tw/docs/quickstart/_index.md @@ -86,13 +86,13 @@ package main import "github.com/gin-gonic/gin" func main() { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) - r.Run() // listen and serve on 0.0.0.0:8080 + router.Run() // listen and serve on 0.0.0.0:8080 } ``` diff --git a/content/zh-tw/docs/testing/_index.md b/content/zh-tw/docs/testing/_index.md index b001ce108..363a5eee6 100644 --- a/content/zh-tw/docs/testing/_index.md +++ b/content/zh-tw/docs/testing/_index.md @@ -19,15 +19,15 @@ type User struct { } func setupRouter() *gin.Engine { - r := gin.Default() - r.GET("/ping", func(c *gin.Context) { + router := gin.Default() + router.GET("/ping", func(c *gin.Context) { c.String(200, "pong") }) return r } func postUser(r *gin.Engine) *gin.Engine { - r.POST("/user/add", func(c *gin.Context) { + router.POST("/user/add", func(c *gin.Context) { var user User c.BindJSON(&user) c.JSON(200, user) @@ -38,7 +38,7 @@ func postUser(r *gin.Engine) *gin.Engine { func main() { r := setupRouter() r = postUser(r) - r.Run(":8080") + router.Run(":8080") } ```