From bf5d312a7433f782b534210bb210ecbf28e93a81 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Thu, 21 Mar 2013 13:55:59 +0100 Subject: [PATCH] Add flag to read assets from local files. --- web/status.go | 15 +++++++++++---- web/web.go | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/web/status.go b/web/status.go index 7f6bf6396d..887867c5aa 100644 --- a/web/status.go +++ b/web/status.go @@ -40,11 +40,18 @@ func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Status: "TODO: add status information here", TargetPools: h.appState.TargetManager.Pools(), } - templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html") - if err != nil { - log.Fatalf("Could not read template: %s", err) + + var t *template.Template + if *localAssets { + t, _ = template.ParseFiles("web/templates/status.html") + } else { + templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html") + if err != nil { + log.Fatalf("Could not read template: %s", err) + } + + t, _ = template.New("status").Parse(string(templateFile)) } - t, _ := template.New("status").Parse(string(templateFile)) t.Execute(w, status) } diff --git a/web/web.go b/web/web.go index b7a9f4350d..6e167e3e66 100644 --- a/web/web.go +++ b/web/web.go @@ -27,6 +27,7 @@ import ( // Commandline flags. var ( listenAddress = flag.String("listenAddress", ":9090", "Address to listen on for web interface.") + localAssets = flag.Bool("localAssets", false, "Read assets/templates from file instead of binary.") ) func StartServing(appState *appstate.ApplicationState) { @@ -36,7 +37,11 @@ func StartServing(appState *appstate.ApplicationState) { http.Handle("/status", &StatusHandler{appState: appState}) http.Handle("/api/", gorest.Handle()) http.Handle("/metrics.json", exporter) - http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler))) + if *localAssets { + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static")))) + } else { + http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler))) + } go http.ListenAndServe(*listenAddress, nil) }