A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
912 B

package responses
import (
"log"
"net/http"
)
// Panic gives a simple error with no template or anything fancy.
func Panic(w http.ResponseWriter, code int, message string) {
w.WriteHeader(code)
w.Write([]byte(message))
}
// Error returns an error page.
func Error(w http.ResponseWriter, r *http.Request, code int, message string) {
v := map[string]interface{}{
"Message": message,
}
w.WriteHeader(code)
if err := RenderTemplate(w, r, "_builtin/errors/generic.gohtml", v); err != nil {
log.Printf("responses.Error: failed to render a pretty error template: %s", err)
w.Write([]byte(message))
}
}
// NotFound returns an HTML 404 page.
func NotFound(w http.ResponseWriter, r *http.Request) {
if err := RenderTemplate(w, r, "_builtin/errors/404.gohtml", nil); err != nil {
log.Printf("responses.NotFound: failed to render a pretty error template: %s", err)
w.Write([]byte("Not Found"))
}
}