build: make frontend embedding optional

This commit is contained in:
jbwfu
2026-03-05 11:36:56 +08:00
parent bc09625708
commit a6db3c8a63
6 changed files with 53 additions and 39 deletions
+3 -11
View File
@@ -1,28 +1,20 @@
//go:build web
package static
import (
"embed"
"io/fs"
"net/http"
)
//go:embed dist/*
var distFS embed.FS
// GetFileSystem 返回嵌入的静态文件系统
func GetFileSystem() http.FileSystem {
subFS, err := fs.Sub(distFS, "dist")
if err != nil {
panic(err)
}
return http.FS(subFS)
}
// GetFS 返回嵌入的 fs.FS
func GetFS() fs.FS {
subFS, err := fs.Sub(distFS, "dist")
if err != nil {
panic(err)
return nil
}
return subFS
}
+16
View File
@@ -0,0 +1,16 @@
//go:build !web
package static
import (
"io/fs"
"os"
)
func GetFS() fs.FS {
return nil
}
func ReadFile(name string) ([]byte, error) {
return nil, os.ErrNotExist
}