diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/json" + "embed" "flag" "fmt" "io/ioutil" @@ -13,6 +14,9 @@ import ( "text/template" ) +//go:embed simple.css/simple.css +var static embed.FS + var appdata string type RuntimeConfig struct { @@ -33,7 +37,8 @@ func main() { c := parseConfig(configPath) http.HandleFunc("/", index(c.Devices, appdata)) http.HandleFunc("/api", api()) - http.HandleFunc("/simple.css", css(appdata)) + http.Handle("/static/", http.StripPrefix("/static/", + http.FileServer(http.FS(static)))) fmt.Printf("Serving at http://%s\n", c.Web.Listen) log.Fatal(http.ListenAndServe(c.Web.Listen.String(), nil)) } @@ -81,17 +86,6 @@ func index(devices DevicesConfig, appdata string) func(http.ResponseWriter, *htt } } -func css(appdata string) func(http.ResponseWriter, *http.Request) { - - path := filepath.Join(appdata, "simple.css") - css := string(mustRead(path)) - - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/css; charset=utf-8") - fmt.Fprint(w, css) - } -} - // mustRead() reads a file and panics if this is not possible. func mustRead(path string) []byte { data, err := ioutil.ReadFile(path) |