mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-15 22:41:19 +00:00
08a99152d6
Co-authored-by: Anbraten <anton@ju60.de>
44 lines
586 B
Go
44 lines
586 B
Go
package web
|
|
|
|
import (
|
|
"embed"
|
|
"io"
|
|
"io/fs"
|
|
"net/http"
|
|
)
|
|
|
|
//go:embed dist/*
|
|
var webFiles embed.FS
|
|
|
|
func HTTPFS() http.FileSystem {
|
|
httpFS, err := fs.Sub(webFiles, "dist")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return http.FS(httpFS)
|
|
}
|
|
|
|
func Lookup(path string) (buf []byte, err error) {
|
|
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
|
|
}
|
|
|
|
func MustLookup(path string) (buf []byte) {
|
|
buf, err := Lookup(path)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return buf
|
|
}
|