2021-09-29 17:34:56 +02:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2022-08-30 01:14:07 +02:00
|
|
|
"io"
|
2021-09-29 17:34:56 +02:00
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed dist/*
|
|
|
|
var webFiles embed.FS
|
|
|
|
|
2021-12-01 15:22:06 +02:00
|
|
|
func HTTPFS() http.FileSystem {
|
2021-09-29 17:34:56 +02: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 15:22:06 +02:00
|
|
|
file, err := HTTPFS().Open(path)
|
2021-09-29 17:34:56 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2022-08-30 01:14:07 +02:00
|
|
|
buf, err = io.ReadAll(file)
|
2021-09-29 17:34:56 +02:00
|
|
|
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
|
|
|
|
}
|