gin controller 写法
func main() { router := gin.Default() router.LoadHTMLGlob("templates/*.tmpl") // 如果使用 LoadHTMLFiles 的话这么做(需要列举所有需要加载的文件,不如上述 LoadHTMLGlob 模式匹配方便): // router.LoadHTMLFiles("templates/template1.html", "templates/template2.html") router.GET("/index", func(c *gin.Context) { c.HTML(http.StatusOK, "index.tmpl", gin.H{ "title": "Main website", }) }) router.Run(":8080") }
view 视图系统写法
{{ define "index.tmpl" }} <html> <h1> {{ .title }} </h1> </html> {{ end }}