87fec6c5ab
The NotFoundHandler previously returned status code 200 because WriteHeader wasn't called.
26 lignes
703 o
Go
26 lignes
703 o
Go
package router
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
var notFoundTemplate = template.Must(template.New("NotFound").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/404.html"))
|
|
|
|
func init() {
|
|
// common
|
|
template.Must(notFoundTemplate.ParseGlob("templates/_*.html"))
|
|
}
|
|
|
|
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
searchForm := NewSearchForm()
|
|
searchForm.HideAdvancedSearch = true
|
|
err := notFoundTemplate.ExecuteTemplate(w, "index.html", NotFoundTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
}
|