Move handler objects to common location to share with RMO

This commit is contained in:
Eli Ribble 2026-03-03 17:08:58 +00:00
parent 87fe5ec2e5
commit 0f6da8e25f
No known key found for this signature in database
33 changed files with 449 additions and 308 deletions

26
html/handler.go Normal file
View file

@ -0,0 +1,26 @@
package html
import (
"context"
"net/http"
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
"github.com/rs/zerolog/log"
)
type handlerFunctionGet[T any] func(context.Context, *http.Request) (*Response[T], *nhttp.ErrorWithStatus)
func MakeGet[T any](f handlerFunctionGet[T]) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
resp, e := f(ctx, r)
if e != nil {
log.Warn().Int("status", e.Status)
http.Error(w, e.Error(), e.Status)
return
}
RenderOrError(w, resp.Template, Content[T]{
C: resp.Content,
})
}
}