mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 10:21:00 +00:00
ed6d3f3cea
- replace togo with go embed - replace httptreemux with gin closes #308
44 lines
597 B
Go
44 lines
597 B
Go
package web
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"io/ioutil"
|
|
"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 = ioutil.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
|
|
}
|