Gin框架-重定向

发布HTTP重定向很容易,支持内部和外部链接

r.GET("/test", func(c *gin.Context) {
    c.Redirect(http.StatusMovedPermanently, "http://www.google.com/")
})

Gin路由重定向,使用如下的HandleContext

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"})
})

Leave a Reply

Your email address will not be published. Required fields are marked *