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 package main
import ( import (
"embed"
"flag" "flag"
"gin-article/handler" "gin-article/handler"
"html/template"
"io/fs"
"log" "log"
"net/http"
"os" "os"
"strconv" "strconv"
"sync" "sync"
@@ -12,6 +16,12 @@ import (
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
//go:embed statics/*
var staticFS embed.FS
//go:embed tmpl/*
var tplFS embed.FS
func main() { func main() {
err := godotenv.Load(".env") err := godotenv.Load(".env")
@@ -21,8 +31,14 @@ func main() {
} }
r := Router() 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") port := flag.Int("p", 88, "the port to listen on")