Files
gothstarter/handlers/shared.go
2024-04-24 19:52:05 +02:00

23 lines
473 B
Go

package handlers
import (
"log/slog"
"net/http"
"github.com/a-h/templ"
)
type HTTPHandler func(w http.ResponseWriter, r *http.Request) error
func Make(h HTTPHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := h(w, r); err != nil {
slog.Error("HTTP handler error", "err", err, "path", r.URL.Path)
}
}
}
func Render(w http.ResponseWriter, r *http.Request, c templ.Component) error {
return c.Render(r.Context(), w)
}