summaryrefslogtreecommitdiff
path: root/render.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-29 02:38:17 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-29 02:38:17 +0300
commit2916082d5ed94ef86ad58bdb7256ae07b214c4f3 (patch)
tree322a0e9172c07457a892f9737839843b8c584864 /render.go
Начальный коммит
Diffstat (limited to 'render.go')
-rw-r--r--render.go24
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)
+}