Noah Petherbridge
2a8a1df6ab
* Initial codebase (lot of work!) * Uses vanilla Go net/http and implements by hand: session cookies backed by Redis; log in/out; CSRF protection; email verification flow; initial database models (User table)
25 lines
660 B
Go
25 lines
660 B
Go
package templates
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// NotFoundPage is an HTTP handler for 404 pages.
|
|
var NotFoundPage = func() http.HandlerFunc {
|
|
return MakeErrorPage("Not Found", "The page you requested was not here.", http.StatusNotFound)
|
|
}()
|
|
|
|
func MakeErrorPage(header string, message string, statusCode int) http.HandlerFunc {
|
|
tmpl := Must("errors/error.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(statusCode)
|
|
if err := tmpl.Execute(w, r, map[string]interface{}{
|
|
"Header": header,
|
|
"Message": message,
|
|
}); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|