32 lines
733 B
Go
32 lines
733 B
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"path"
|
|
)
|
|
|
|
func displayTmpl(w http.ResponseWriter, page string, vars map[string]interface{}) {
|
|
if t, err := template.ParseGlob(path.Join(StaticDir, "*.html")); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
} else {
|
|
t.ExecuteTemplate(w, page, vars)
|
|
}
|
|
}
|
|
|
|
func displayTmplError(w http.ResponseWriter, statusCode int, page string, vars map[string]interface{}) {
|
|
w.WriteHeader(statusCode)
|
|
displayTmpl(w, page, vars)
|
|
}
|
|
|
|
func displayMsg(w http.ResponseWriter, msg string, statusCode int) {
|
|
w.WriteHeader(statusCode)
|
|
|
|
label := "error"
|
|
if statusCode < 400 {
|
|
label = "message"
|
|
}
|
|
|
|
displayTmpl(w, "message.html", map[string]interface{}{label: msg})
|
|
}
|