This commit is contained in:
2023-03-10 11:11:48 +08:00
parent 96338dd73e
commit daff2be9b6
7 changed files with 85 additions and 55 deletions
-16
View File
@@ -1,13 +1,9 @@
package main
import (
"embed"
"flag"
"gin-article/handler"
"html/template"
"io/fs"
"log"
"net/http"
"os"
"strconv"
"sync"
@@ -16,11 +12,7 @@ import (
"github.com/joho/godotenv"
)
//go:embed tmpl/* statics/**/*
var f embed.FS
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
@@ -28,14 +20,6 @@ func main() {
}
r := Router()
// 静态文件也打包
tmpl, _ := template.ParseFS(f, "tmpl/*")
r.SetHTMLTemplate(tmpl)
staticsFS, _ := fs.Sub(f, "statics")
r.StaticFS("/statics", http.FS(staticsFS))
//r.LoadHTMLGlob("tmpl/*")
//r.Static("/statics", "./statics")
port := flag.Int("p", 88, "the port to listen on")