diff options
author | Jakob Borg <jakob@kastelo.net> | 2023-07-10 08:33:09 +0200 |
---|---|---|
committer | Jakob Borg <jakob@kastelo.net> | 2023-07-10 08:33:09 +0200 |
commit | 2fcf7006e63c546735bc12d5a675c323e6fd27cc (patch) | |
tree | 12eb44449681c4629ce884fb009e6e984acd6b75 | |
parent | bf61e485a6e3b51b87b97c183325302696508241 (diff) | |
download | syncthing-2fcf7006e63c546735bc12d5a675c323e6fd27cc.tar.gz syncthing-2fcf7006e63c546735bc12d5a675c323e6fd27cc.zip |
cmd/ursrv: Embed static assets
-rw-r--r-- | cmd/ursrv/main.go | 8 |
1 files 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() |