1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02:00
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

39 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
}