Gin-返回数据-HTML模板语言

2020-07-06  本文已影响0人  诗意_面包

Go-Gin

package main

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

func main()  {
    app := gin.Default()
    // 指明html加载文件目录
    app.LoadHTMLGlob("./html/*")
    app.Handle("GET", "/", func(context *gin.Context) {
        context.HTML(http.StatusOK, "index.html", gin.H{
            "title": "首页",
            "fullpath": context.FullPath(),
        })
    })
    app.Run()
}

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{.title}}</title>
</head>
<body>
    <p>{{.fullpath}}</p>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读