EasyAudioEncode/internal/web/api/static/static.go

22 lines
493 B
Go
Raw Normal View History

2025-12-25 17:01:46 +08:00
package static
import (
"embed"
"io/fs"
"net/http"
)
//go:embed www/*
var www embed.FS
func FileSystem() http.FileSystem {
// 将嵌入的根目录定位到 www 子目录,便于通过 /ui 直接访问 index.html
// 例如c.FileFromFS("index.html", FileSystem()) 实际读取的是 www/index.html
sub, err := fs.Sub(www, "www")
if err != nil {
// 子目录创建失败则回退为原始嵌入根(不推荐,但避免崩溃)
return http.FS(www)
}
return http.FS(sub)
}