Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/notFoundHandler.go
Atvaark 45d479a9be Return status code 404 on 404 page
The NotFoundHandler previously returned status code 200
because WriteHeader wasn't called.
2017-05-07 16:18:35 +02:00

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)
}
}