Files
projectreshoot/internal/handler/index.go

29 lines
584 B
Go

package handler
import (
"net/http"
"projectreshoot/internal/view/page"
)
// Handles responses to the / path. Also serves a 404 Page for paths that
// don't have explicit handlers
func Root() http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
page, err := ErrorPage(http.StatusNotFound)
if err != nil {
// TODO: add logger for this
}
err = page.Render(r.Context(), w)
if err != nil {
// TODO: add logger for this
}
return
}
page.Index().Render(r.Context(), w)
},
)
}