woodpecker/web/web.go
Lukas 680d003a29
Add linter revive (#554)
* Add linter revive

* Add underscore to variable name to prevent shadowing

* Remove unnecessary leading underscore

* Revert changes to vendor file

* export ConfigFetcher as interface

* no 'yoda conditions'

* rename envsubst

Co-authored-by: 6543 <6543@obermui.de>
2021-12-01 14:22:06 +01:00

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
}