mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-04-20 16:40:29 +00:00
39 lines
917 B
Go
39 lines
917 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// NotFoundHandler handles 404 errors
|
|
type NotFoundHandler struct {
|
|
BaseUIHandler
|
|
}
|
|
|
|
func (h *NotFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
RenderNotFound(w, r, &h.BaseUIHandler)
|
|
}
|
|
|
|
// RenderNotFound renders the 404 page template.
|
|
// Use this from other handlers when a resource is not found.
|
|
func RenderNotFound(w http.ResponseWriter, r *http.Request, h *BaseUIHandler) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
meta := NewPageMeta(
|
|
"404 - Lost at Sea | "+h.ClientShortName,
|
|
"Page not found - the requested resource doesn't exist on "+h.ClientShortName,
|
|
).WithRobots("noindex").
|
|
WithSiteName(h.ClientShortName)
|
|
|
|
data := struct {
|
|
PageData
|
|
Meta *PageMeta
|
|
}{
|
|
PageData: NewPageData(r, h),
|
|
Meta: meta,
|
|
}
|
|
|
|
if err := h.Templates.ExecuteTemplate(w, "404", data); err != nil {
|
|
http.Error(w, "Page not found", http.StatusNotFound)
|
|
}
|
|
}
|