2021-09-29 15:34:56 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2022-08-29 23:14:07 +00:00
|
|
|
"io"
|
2021-09-29 15:34:56 +00:00
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed dist/*
|
|
|
|
var webFiles embed.FS
|
|
|
|
|
2023-03-20 23:48:15 +00:00
|
|
|
func HTTPFS() (http.FileSystem, error) {
|
2021-09-29 15:34:56 +00:00
|
|
|
httpFS, err := fs.Sub(webFiles, "dist")
|
|
|
|
if err != nil {
|
2023-03-20 23:48:15 +00:00
|
|
|
return nil, err
|
2021-09-29 15:34:56 +00:00
|
|
|
}
|
2023-03-20 23:48:15 +00:00
|
|
|
return http.FS(httpFS), nil
|
2021-09-29 15:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Lookup(path string) (buf []byte, err error) {
|
2023-03-20 23:48:15 +00:00
|
|
|
httpFS, err := HTTPFS()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
file, err := httpFS.Open(path)
|
2021-09-29 15:34:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2022-08-29 23:14:07 +00:00
|
|
|
buf, err = io.ReadAll(file)
|
2021-09-29 15:34:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|