Gin series – redirection

Time:2020-7-11

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()
	//HTTP redirection
	r.GET("/index", func(c *gin.Context) {
		//c.JSON(http.StatusOK, gin.H{
		//	"status": "ok",
		//})
		//Jump to SOGO
		c.Redirect(http.StatusMovedPermanently, "https://www.sogo.com")
	})

	//Route redirection
	r.GET("/luyou", func(c *gin.Context) {
		//Jump to the route processing function corresponding to / luyou2
		C. Request.URL.Path  ="/ luyou2" // modify the requested URL
		r. Handlecontext (c) // continue with subsequent processing
	})
	r.GET("/luyou2", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"Message": route redirection,
		})
	})
	r.Run(":9090")
}