重組前檢查點:根目錄 main package

This commit is contained in:
2026-10-03 09:23:38 +08:00
commit f373cb8d37
45 changed files with 5332 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
package main
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets
var assetsFS embed.FS
// staticHandler 以 /static/ 前綴提供 assets 內的靜態檔案
// (Tailwind 建置輸出的 CSS 等),並允許瀏覽器快取。
func staticHandler() http.Handler {
sub, err := fs.Sub(assetsFS, "assets")
if err != nil {
panic(err) // embed 路徑固定,僅防呆
}
fileServer := http.StripPrefix("/static/", http.FileServerFS(sub))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// 內容隨執行檔重建,過期重抓即可。
w.Header().Set("Cache-Control", "public, max-age=3600")
fileServer.ServeHTTP(w, r)
})
}