EasyAudioEncode/internal/web/api/static/static.go
2025-12-25 17:01:46 +08:00

22 lines
493 B
Go
Raw Permalink 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"
)
//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)
}