重定向
HTTP 重定向很容易。 内部、外部重定向均支持。
router.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.google.com/")})
通过 POST 方法进行 HTTP 重定向。请参考 issue:#444
router.POST("/test", func(c *gin.Context) { c.Redirect(http.StatusFound, "/foo")})
路由重定向,使用 HandleContext
:
router.GET("/test", func(c *gin.Context) { c.Request.URL.Path = "/test2" router.HandleContext(c)})router.GET("/test2", func(c *gin.Context) { c.JSON(200, gin.H{"hello": "world"})})