WIP, but this is going to become my new blog CMS
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
729 B

package main
import (
"fmt"
"net/http"
"strings"
)
type errorData struct {
Title string
Message string
}
func serve404(w http.ResponseWriter, r *http.Request) {
serveError(w, r, fmt.Sprintf("%s was not found", r.RequestURI), http.StatusNotFound)
}
func serveError(w http.ResponseWriter, r *http.Request, message string, status int) {
if !strings.Contains(strings.ToLower(r.Header.Get("Accept")), contentTypeHTML) {
http.Error(w, message, status)
return
}
title := fmt.Sprintf("%d %s", status, http.StatusText(status))
if message == "" {
message = http.StatusText(status)
}
render(w, templateError, &renderData{
Data: &errorData{
Title: title,
Message: message,
},
})
w.WriteHeader(status)
}