Initial commit

This commit is contained in:
nemunaire
2018-11-12 23:31:10 +01:00
commit b99a321ded
35 changed files with 11997 additions and 0 deletions

31
tmpl.go Normal file
View File

@@ -0,0 +1,31 @@
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})
}