blob: 8b39090a77b1e7d7723c4445ea2bb4dee2ef2a7e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
}
|