package main
import (
"html/template"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.SetFuncMap(template.FuncMap{
"safe": func(str string) template.HTML {
return template.HTML(str)
},
})
router.LoadHTMLFiles("./index.tmpl")
router.GET("/index", func(c *gin.Context) {
c.HTML(200, "index.tmpl", "<a href='lizhouwen.com'>1232</a>")
})
router.Run(":17111")
}
index.tmpl
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>bert</title>
</head>
<body>
<h1>2134</h1>
<div>{{ . | safe }}</div>
</body>
</html>
有疑问加站长微信联系(非本文作者)