Move handler objects to common location to share with RMO
This commit is contained in:
parent
87fe5ec2e5
commit
0f6da8e25f
33 changed files with 449 additions and 308 deletions
26
html/handler.go
Normal file
26
html/handler.go
Normal 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue