Update pkglib to latest

This commit is contained in:
Tom Wiesing 2024-04-08 23:54:32 +02:00
parent 2d1f3e3819
commit 0c50b5e182
No known key found for this signature in database
10 changed files with 36 additions and 16 deletions

View file

@ -89,8 +89,9 @@ func (admin *Admin) createUser(context.Context) http.Handler {
},
FieldTemplate: assets.PureCSSFieldTemplate,
Template: tpl.Template(),
TemplateContext: templating.FormTemplateContext(tpl),
Template: tpl.Template(),
TemplateContext: templating.FormTemplateContext(tpl),
LogTemplateError: tpl.LogTemplateError,
Validate: func(r *http.Request, values map[string]string) (cu createUserResult, err error) {
cu.User, cu.Passsword, cu.Admin = values["username"], values["password"], values["admin"] == field.CheckboxChecked

View file

@ -57,5 +57,12 @@ func (h *Handling) Redirect(Handler content.RedirectFunc) http.Handler {
}
func (h *Handling) WriteHTML(context any, err error, template *template.Template, w http.ResponseWriter, r *http.Request) error {
return content.WriteHTMLI(context, err, template, h.HTMLInterceptor(), w, r)
return LogTemplateError(r, content.WriteHTMLI(context, err, template, h.HTMLInterceptor(), w, r))
}
func LogTemplateError(r *http.Request, err error) error {
if err != nil {
zerolog.Ctx(r.Context()).Err(err).Str("path", r.URL.String()).Msg("error rendering template")
}
return err
}

View file

@ -34,6 +34,11 @@ func (tpl *Template[C]) Template() *template.Template {
return baseTemplate
}
// LogTepmplateError logs a non-nil error into the logger found in the request
func (*Template[C]) LogTemplateError(r *http.Request, err error) {
handling.LogTemplateError(r, err)
}
// Context generates the context to pass to an instance of the template returned by Template.
func (tpl *Template[C]) Context(r *http.Request, c C, funcs ...FlagFunc) (ctx *tContext[C]) {
ctx = tpl.context(r, funcs...)