gin 打包静态文件·
作者:
vins | 来源:发表于
2023-11-03 10:29 被阅读0次package main
import (
"embed"
"github.com/gin-gonic/gin"
"html/template"
"log"
"net/http"
)
//go:embed templates/**/*.html
var templates embed.FS
//go:embed static/*
var staticFiles embed.FS
func main() {
r := gin.Default()
r.StaticFS("/static", http.FS(staticFiles))
tmpl, err := template.ParseFS(templates, "templates/**/*.html")
if err != nil {
log.Fatal(err)
}
r.SetHTMLTemplate(tmpl)
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", nil)
})
log.Fatal(r.Run(":9191"))
}
![](https://img.haomeiwen.com/i15700727/5d763e721b46e5dc.png)
image.png
本文标题:gin 打包静态文件·
本文链接:https://www.haomeiwen.com/subject/kwkoidtx.html
网友评论