error-pages/internal/http/handlers/notfound/handler.go

29 lines
744 B
Go
Raw Normal View History

2021-10-06 17:38:00 +00:00
package notfound
import (
"github.com/valyala/fasthttp"
"gh.tarampamp.am/error-pages/internal/config"
"gh.tarampamp.am/error-pages/internal/http/core"
"gh.tarampamp.am/error-pages/internal/options"
"gh.tarampamp.am/error-pages/internal/tpl"
)
type (
templatePicker interface {
// Pick the template name for responding.
Pick() string
}
renderer interface {
Render(content []byte, props tpl.Properties) ([]byte, error)
}
2021-10-06 17:38:00 +00:00
)
// NewHandler creates handler missing requests handling.
func NewHandler(cfg *config.Config, p templatePicker, rdr renderer, opt options.ErrorPage) fasthttp.RequestHandler {
2021-10-06 17:38:00 +00:00
return func(ctx *fasthttp.RequestCtx) {
core.RespondWithErrorPage(ctx, cfg, p, rdr, "404", fasthttp.StatusNotFound, opt)
2021-10-06 17:38:00 +00:00
}
}