From 2fcf7006e63c546735bc12d5a675c323e6fd27cc Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 10 Jul 2023 08:33:09 +0200 Subject: [PATCH] cmd/ursrv: Embed static assets --- cmd/ursrv/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/ursrv/main.go b/cmd/ursrv/main.go index 76014d268..489b4ffca 100644 --- a/cmd/ursrv/main.go +++ b/cmd/ursrv/main.go @@ -10,6 +10,7 @@ import ( "bytes" "crypto/tls" "database/sql" + "embed" "encoding/json" "html/template" "io" @@ -45,6 +46,9 @@ type CLI struct { GeoIPPath string `env:"UR_GEOIP" default:"GeoLite2-City.mmdb"` } +//go:embed static +var statics embed.FS + var ( tpl *template.Template compilerRe = regexp.MustCompile(`\(([A-Za-z0-9()., -]+) \w+-\w+(?:| android| default)\) ([\w@.-]+)`) @@ -168,7 +172,7 @@ func main() { // Template - fd, err := os.Open("static/index.html") + fd, err := statics.Open("static/index.html") if err != nil { log.Fatalln("template:", err) } @@ -224,7 +228,7 @@ func main() { http.HandleFunc("/performance.json", srv.performanceHandler) http.HandleFunc("/blockstats.json", srv.blockStatsHandler) http.HandleFunc("/locations.json", srv.locationsHandler) - http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + http.Handle("/static/", http.FileServer(http.FS(statics))) go srv.cacheRefresher()