gin/html-xuanran/main.go

22 lines
366 B
Go

package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
//html渲染
func main() {
//创建路由
r := gin.Default()
//加载模板文件
r.LoadHTMLGlob("./templates/*")
r.GET("/index", func(c *gin.Context) {
//根据文件名渲染
//JSON将title替换
c.HTML(http.StatusOK, "index.tmpl", gin.H{"title": "我的标题"})
})
r.Run(":8000")
}