Use constants for blob bucket keys.

This commit is contained in:
Johannes 'fish' Ziemke 2013-03-19 16:11:55 +01:00
parent 59f8ba9121
commit a5d31cb239
2 changed files with 9 additions and 4 deletions

View File

@ -8,6 +8,11 @@ import (
"net/http" "net/http"
) )
const (
TemplateFiles = "templates"
StaticFiles = "static"
)
func GetFile(bucket string, name string) ([]byte, error) { func GetFile(bucket string, name string) ([]byte, error) {
reader := bytes.NewReader(files[bucket][name]) reader := bytes.NewReader(files[bucket][name])
gz, err := gzip.NewReader(reader) gz, err := gzip.NewReader(reader)
@ -30,7 +35,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
name = "index.html" name = "index.html"
} }
file, err := GetFile("static", name) file, err := GetFile(StaticFiles, name)
if err != nil { if err != nil {
if err != io.EOF { if err != io.EOF {
log.Printf("Could not get file: %s", err) log.Printf("Could not get file: %s", err)
@ -38,6 +43,6 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }
w.Header().Set("Content-Type", types["static"][name]) w.Header().Set("Content-Type", types[StaticFiles][name])
w.Write(file) w.Write(file)
} }

View File

@ -40,11 +40,11 @@ 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(),
} }
template_file, err := blob.GetFile("templates", "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(template_file)) t, _ := template.New("status").Parse(string(templateFile))
t.Execute(w, status) t.Execute(w, status)
} }