2021-10-06 17:38:00 +00:00
|
|
|
package notfound
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/valyala/fasthttp"
|
2023-04-07 10:42:00 +00:00
|
|
|
|
|
|
|
"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.
|
2023-04-07 10:42:00 +00:00
|
|
|
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) {
|
2023-04-07 10:42:00 +00:00
|
|
|
core.RespondWithErrorPage(ctx, cfg, p, rdr, "404", fasthttp.StatusNotFound, opt)
|
2021-10-06 17:38:00 +00:00
|
|
|
}
|
|
|
|
}
|