From 07cbe116a058f13026fa6b23f675155968d47cc3 Mon Sep 17 00:00:00 2001 From: chainhelen Date: Wed, 30 May 2018 09:19:04 +0800 Subject: [PATCH 1/3] Add and fix the explanation of `HandleContext` (#1371) Reference this issue #1323 1. There isn't any eg about `HandleContext` 2. The `c.Request.Path` of `HandleContext` Comment is not right Based on the above two points, I pull this request. If you think it's unnecessary, I will close this. Thx. --- README.md | 16 ++++++++++++++-- gin.go | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 51a807b5..fd5c1755 100644 --- a/README.md +++ b/README.md @@ -1082,14 +1082,26 @@ Gin allow by default use only one html.Template. Check [a multitemplate render]( ### Redirects -Issuing a HTTP redirect is easy: +Issuing a HTTP redirect is easy. Both internal and external locations are supported. ```go r.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/") }) ``` -Both internal and external locations are supported. + + +Issuing a Router redirect, use `HandleContext` like below. + +``` go +r.GET("/test", func(c *gin.Context) { + c.Request.URL.Path = "/test2" + r.HandleContext(c) +}) +r.GET("/test2", func(c *gin.Context) { + c.JSON(200, gin.H{"hello": "world"}) +}) +``` ### Custom Middleware diff --git a/gin.go b/gin.go index 4205eff0..b91fc2fa 100644 --- a/gin.go +++ b/gin.go @@ -329,7 +329,7 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) { } // HandleContext re-enter a context that has been rewritten. -// This can be done by setting c.Request.Path to your new target. +// This can be done by setting c.Request.URL.Path to your new target. // Disclaimer: You can loop yourself to death with this, use wisely. func (engine *Engine) HandleContext(c *Context) { c.reset() From c2f083fc953073a5cfdcdd386fb3c7d1f004c2cc Mon Sep 17 00:00:00 2001 From: MW Lim Date: Thu, 31 May 2018 11:41:45 +0800 Subject: [PATCH 2/3] minor typo in routergroup.go (#1360) --- routergroup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routergroup.go b/routergroup.go index 5e681c1c..53045d10 100644 --- a/routergroup.go +++ b/routergroup.go @@ -139,7 +139,7 @@ func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRou return group.returnObj() } -// StaticFile registers a single route in order to server a single file of the local filesystem. +// StaticFile registers a single route in order to serve a single file of the local filesystem. // router.StaticFile("favicon.ico", "./resources/favicon.ico") func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes { if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") { From caf3e350a548af1add9def68087ac53d1d000caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E6=AC=A7?= Date: Thu, 31 May 2018 14:13:40 +0800 Subject: [PATCH 3/3] doc: update readme for adding binding about skip validate (#1359) * update readme for adding binding about skip validate * update readme for adding binding about skip validate --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fd5c1755..0bac65b2 100644 --- a/README.md +++ b/README.md @@ -572,6 +572,10 @@ $ curl -v -X POST \ {"error":"Key: 'Login.Password' Error:Field validation for 'Password' failed on the 'required' tag"} ``` +**Skip validate** + +When running the above example using the above the `curl` command, it returns error. Because the example use `binding:"required"` for `Password`. If use `binding:"-"` for `Password`, then it will not return error when running the above example again. + ### Custom Validators It is also possible to register custom validators. See the [example code](examples/custom-validation/server.go).