package main
import "github.com/gin-gonic/gin"
func main() {
//请求重定向
r := gin.Default()
r.GET("/index", func(context *gin.Context) {
/*301: 永久重定向
常用的例如域名跳转:http:**** => https:****
302: 临时重定向
需要向服务端请求是否过期,过期返回新数据,没过期返回状态吗302,然后客户端重定向,
期间差别主要在于数据包的大小(没有过期的情况下,不需要再在数据包中附加数据返回,从而加速网络传输,提升速度)*/
context.Redirect(301, "https://www.bilibili.com/")
})
//路由重定向
r.GET("/a", func(context *gin.Context) {
context.Request.URL.Path = "/b"
r.HandleContext(context)
})
r.GET("/b", func(context *gin.Context) {
context.String(200, "are you ok?")
})
r.Run()
}