Add flag to read assets from local files.

This commit is contained in:
Johannes 'fish' Ziemke 2013-03-21 13:55:59 +01:00
parent 1f80b17cb7
commit bf5d312a74
2 changed files with 17 additions and 5 deletions

View file

@ -40,11 +40,18 @@ func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Status: "TODO: add status information here", Status: "TODO: add status information here",
TargetPools: h.appState.TargetManager.Pools(), TargetPools: h.appState.TargetManager.Pools(),
} }
var t *template.Template
if *localAssets {
t, _ = template.ParseFiles("web/templates/status.html")
} else {
templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html") templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html")
if err != nil { if err != nil {
log.Fatalf("Could not read template: %s", err) 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) t.Execute(w, status)
} }

View file

@ -27,6 +27,7 @@ import (
// Commandline flags. // Commandline flags.
var ( var (
listenAddress = flag.String("listenAddress", ":9090", "Address to listen on for web interface.") 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) { func StartServing(appState *appstate.ApplicationState) {
@ -36,7 +37,11 @@ func StartServing(appState *appstate.ApplicationState) {
http.Handle("/status", &StatusHandler{appState: appState}) http.Handle("/status", &StatusHandler{appState: appState})
http.Handle("/api/", gorest.Handle()) http.Handle("/api/", gorest.Handle())
http.Handle("/metrics.json", exporter) http.Handle("/metrics.json", exporter)
if *localAssets {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
} else {
http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler))) http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
}
go http.ListenAndServe(*listenAddress, nil) go http.ListenAndServe(*listenAddress, nil)
} }