mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-25 09:50:31 +00:00
46452fbd84
Signed-off-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@obermui.de>
38 lines
546 B
Go
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
|
|
}
|