mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
d40e8879d1
* 🎨 style(CHANGELOG.md): add UNRELEASED section 🔧 chore(notfound/handler.go): refactor to use core.RespondWithErrorPage 🔧 chore(http/server.go): pass config, templatePicker, renderer and options to notfoundHandler 🔧 chore(hurl/404.hurl): update test to expect HTML response instead of plain text * 📝 docs(CHANGELOG.md): fix typo in changed section * 🔥 chore(CHANGELOG.md): release version 2.22.0 🔥 chore(flags.go): remove unused code for serve command
29 lines
744 B
Go
29 lines
744 B
Go
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)
|
|
}
|
|
)
|
|
|
|
// NewHandler creates handler missing requests handling.
|
|
func NewHandler(cfg *config.Config, p templatePicker, rdr renderer, opt options.ErrorPage) fasthttp.RequestHandler {
|
|
return func(ctx *fasthttp.RequestCtx) {
|
|
core.RespondWithErrorPage(ctx, cfg, p, rdr, "404", fasthttp.StatusNotFound, opt)
|
|
}
|
|
}
|