This commit is contained in:
2023-03-09 14:34:01 +08:00
parent bf84bbfffd
commit 9f97e99353
+18 -2
View File
@@ -1,9 +1,13 @@
package main
import (
"embed"
"flag"
"gin-article/handler"
"html/template"
"io/fs"
"log"
"net/http"
"os"
"strconv"
"sync"
@@ -12,6 +16,12 @@ import (
"github.com/joho/godotenv"
)
//go:embed statics/*
var staticFS embed.FS
//go:embed tmpl/*
var tplFS embed.FS
func main() {
err := godotenv.Load(".env")
@@ -21,8 +31,14 @@ func main() {
}
r := Router()
r.LoadHTMLGlob("tmpl/*")
r.Static("/statics", "./statics")
// 静态文件也打包
tmpl, _ := template.ParseFS(tplFS, "tmpl/*")
r.SetHTMLTemplate(tmpl)
staticFS, _ := fs.Sub(staticFS, "static")
r.StaticFS("/static", http.FS(staticFS))
//r.LoadHTMLGlob("tmpl/*")
//r.Static("/statics", "./statics")
port := flag.Int("p", 88, "the port to listen on")