22 lines
493 B
Go
22 lines
493 B
Go
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)
|
||
}
|