woodpecker/web/web.go
Lauris BH 46452fbd84
Update Go dependencies and minimal Go version to 1.20 (#1650)
Signed-off-by: 6543 <6543@obermui.de>
Co-authored-by: 6543 <6543@obermui.de>
2023-03-21 00:48:15 +01:00

38 lines
546 B
Go

package web
import (
"embed"
"io"
"io/fs"
"net/http"
)
//go:embed dist/*
var webFiles embed.FS
func HTTPFS() (http.FileSystem, error) {
httpFS, err := fs.Sub(webFiles, "dist")
if err != nil {
return nil, err
}
return http.FS(httpFS), nil
}
func Lookup(path string) (buf []byte, err error) {
httpFS, err := HTTPFS()
if err != nil {
return nil, err
}
file, err := httpFS.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
buf, err = io.ReadAll(file)
if err != nil {
return nil, err
}
return buf, nil
}