gin 页面重定向


两种gin页面重定向方式

redirect:

package main
 
import (
    "github.com/gin-gonic/gin"
    "net/http"
)
 
 
func main() {
 
    r := gin.Default()
 
    r.GET("/redirect", func(c *gin.Context) {
        c.Redirect(http.StatusMovedPermanently,"http://www.baidu.com")
    })
 
    r.Run(":8080")
}

html rendering:

func main() {
    router := gin.Default()
    router.LoadHTMLGlob("templates/*")

    router.GET("/index", func(c *gin.Context) {
        c.HTML(http.StatusOK, "index.tmpl", gin.H{
            "title": "Main website",
        })
    })
    router.Run(":8080")
}

其中 

router.LoadHTMLGlob("templates/*")是设置前端页面目录


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM