gin 页面重定向

谁说我不能喝 提交于 2019-12-11 16:29:52

两种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/*")是设置前端页面目录
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!