diff options
Diffstat (limited to 'render.go')
-rw-r--r-- | render.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/render.go b/render.go new file mode 100644 index 0000000..8b39090 --- /dev/null +++ b/render.go @@ -0,0 +1,24 @@ +package mux + +import ( + "context" + "io" + "log/slog" + "net/http" +) + +type Renderer interface { + Render(context.Context, io.Writer) error +} + +func Render(w http.ResponseWriter, r *http.Request, renderable Renderer) { + if err := renderable.Render(r.Context(), w); err != nil { + slog.ErrorContext(r.Context(), "failed render template", slog.Any("err", err)) + } +} + +type RendererFunc func(context.Context, io.Writer) error + +func (r RendererFunc) Render(ctx context.Context, w io.Writer) error { + return r(ctx, w) +} |