zdravko/internal/handlers/404.go

33 lines
689 B
Go

package handlers
import (
"fmt"
"net/http"
"text/template"
"code.tjo.space/mentos1386/zdravko/web/templates"
"code.tjo.space/mentos1386/zdravko/web/templates/components"
)
func (h *BaseHandler) Error404(w http.ResponseWriter, r *http.Request) {
ts, err := template.ParseFS(templates.Templates,
"components/base.tmpl",
"pages/404.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNotFound)
err = ts.ExecuteTemplate(w, "base", &components.Base{
Page: nil,
Pages: Pages,
})
if err != nil {
fmt.Println("Error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}