Use go embed for web files and remove httptreemux (#382)

- replace togo with go embed
- replace httptreemux with gin

closes #308
This commit is contained in:
Anbraten
2021-09-29 17:34:56 +02:00
committed by GitHub
parent a82d569bd1
commit ed6d3f3cea
26 changed files with 62 additions and 12984 deletions

44
web/web.go Normal file
View File

@@ -0,0 +1,44 @@
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
}