2021-09-29 15:34:56 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"io/fs"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed dist/*
|
|
|
|
var webFiles embed.FS
|
|
|
|
|
2021-12-01 13:22:06 +00:00
|
|
|
func HTTPFS() http.FileSystem {
|
2021-09-29 15:34:56 +00:00
|
|
|
httpFS, err := fs.Sub(webFiles, "dist")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.FS(httpFS)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Lookup(path string) (buf []byte, err error) {
|
2021-12-01 13:22:06 +00:00
|
|
|
file, err := HTTPFS().Open(path)
|
2021-09-29 15:34:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
buf, err = ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustLookup(path string) (buf []byte) {
|
|
|
|
buf, err := Lookup(path)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|