Check out example codes for "gin middleware redirect". It will help you in understanding the concepts better.

Code Example 1

//This is auth redirect example
func my_middleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		_, err := c.Request.Cookie("auth")
		if err == http.ErrNoCookie {
			c.Redirect(http.StatusTemporaryRedirect, "example.com/redirect")
			c.AbortWithStatus(http.StatusTemporaryRedirect)
		}
		if err != nil {
			// some other error
			http.Error(c.Writer, err.Error(), http.StatusInternalServerError)
			c.AbortWithStatus(http.StatusInternalServerError)
		}
		c.Next()
	}
}

Learn ReactJs, React Native from akashmittal.com