update
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user