summaryrefslogblamecommitdiff
path: root/render.go
blob: 8b39090a77b1e7d7723c4445ea2bb4dee2ef2a7e (plain) (tree)























                                                                                              
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)
}