diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2024-05-26 22:06:44 +0200 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2024-05-26 22:06:44 +0200 |
commit | faa296075f5ea2d8e01004b46b036997f9529d99 (patch) | |
tree | 5d5e2cb693302dd7239aa02a183d2b0efff242c2 /src/http/tpl.go | |
parent | 006c0028106425abb3f718b2e86349dee5b7a2ea (diff) |
Clean out Get/SetRequestLogger from apiutil
Diffstat (limited to 'src/http/tpl.go')
-rw-r--r-- | src/http/tpl.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/http/tpl.go b/src/http/tpl.go index 42341a2..452f444 100644 --- a/src/http/tpl.go +++ b/src/http/tpl.go @@ -80,10 +80,12 @@ func (a *api) executeTemplate( tpl *template.Template, payload interface{}, ) { - - tplData := a.newTPLData(r, payload) - - buf := new(bytes.Buffer) + var ( + ctx = r.Context() + logger = a.params.Logger + tplData = a.newTPLData(r, payload) + buf = new(bytes.Buffer) + ) err := tpl.Execute(buf, tplData) if errors.Is(err, post.ErrPostNotFound) { @@ -91,7 +93,7 @@ func (a *api) executeTemplate( return } else if err != nil { apiutil.InternalServerError( - rw, r, fmt.Errorf("rendering template: %w", err), + ctx, logger, rw, "rendering template: %w", err, ) return } @@ -114,12 +116,15 @@ func (a *api) renderDumbTplHandler(tplName string) http.Handler { tpl := a.mustParseBasedTpl(tplName) return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - - tplData := a.newTPLData(r, nil) + var ( + ctx = r.Context() + logger = a.params.Logger + tplData = a.newTPLData(r, nil) + ) if err := tpl.Execute(rw, tplData); err != nil { apiutil.InternalServerError( - rw, r, fmt.Errorf("rendering %q: %w", tplName, err), + ctx, logger, rw, "rendering %q: %w", tplName, err, ) return } |