2026-01-30 18:21:27 +00:00
|
|
|
package html
|
2026-01-07 15:34:09 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Respond with an error that is visible to the user
|
2026-01-19 21:21:02 +00:00
|
|
|
func RespondError(w http.ResponseWriter, m string, e error, s int) {
|
2026-01-07 15:34:09 +00:00
|
|
|
log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error")
|
|
|
|
|
http.Error(w, m, s)
|
|
|
|
|
}
|
2026-03-03 17:08:58 +00:00
|
|
|
|
|
|
|
|
type Response[T any] struct {
|
|
|
|
|
Content T
|
|
|
|
|
Template string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewResponse[T any](template string, content T) *Response[T] {
|
|
|
|
|
return &Response[T]{
|
|
|
|
|
Content: content,
|
|
|
|
|
Template: template,
|
|
|
|
|
}
|
|
|
|
|
}
|