Files
MailUI4Agents/server/internal/static/static.go

38 lines
781 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package static
import (
"embed"
"io/fs"
"net/http"
"sync"
)
//go:embed static
var staticFS embed.FS
var (
indexHTML []byte
once sync.Once
)
// GetIndex 返回入口页。
//
// index.html 缺失时回退到 placeholder.html前端产物不进版本库
// 新克隆里只有占位页。回退而不是报错是故意的 ——
// 只改后端的人应当能直接 go run 起来调 API而不必先装 node。
func GetIndex() []byte {
once.Do(func() {
if data, err := fs.ReadFile(staticFS, "static/index.html"); err == nil {
indexHTML = data
return
}
indexHTML, _ = fs.ReadFile(staticFS, "static/placeholder.html")
})
return indexHTML
}
func Handler() http.Handler {
sub, _ := fs.Sub(staticFS, "static")
return http.FileServer(http.FS(sub))
}