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>
![](https://static.studygolang.com/200415/165ae717e1ab7c90797cfeaf0b0e87f8.png)
image.png
有疑问加站长微信联系(非本文作者)
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)