助力软件开发企业降本增效 PHP / java源码系统,只需一次付费,代码终身使用! 广告
HTML输出 === 简单的: ~~~ func main() { router := gin.Default() router.LoadHTMLGlob("templates/*") // 目录 下不能有其他文件夹 不会会报错 //router.LoadHTMLFiles("templates/template1.html", "templates/template2.html") router.GET("/index", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", gin.H{ "Title": "Main website", }) }) router.Run(":8080") } ~~~ 多级: ~~~ import ( "github.com/gin-gonic/gin" "net/http" ) func main() { app := gin.Default() app.LoadHTMLGlob("temp/**/*") app.GET("/home", func(c *gin.Context) { c.HTML(http.StatusOK,"posts/index.html",gin.H{ "Title":"Jell", }) }) app.Run(":8085") } ~~~ 感觉这个也太麻烦了把! ~~~ {{ define "posts/index.html"}} <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="renderer" content="webkit"> <title></title> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://cdn.bootcdn.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script> <script src="https://cdn.bootcdn.net/npm/respond.js@1.4.2/dest/respond.min.js"></script> <![endif]--> </head> <body> {{.Title}} </body> </html> {{ end }} ~~~