Pass in ResponseBuilder instead
This commit is contained in:
parent
ef122ccaea
commit
00090ec2bd
11
server.go
11
server.go
@ -120,7 +120,7 @@ const (
|
||||
numServeStages
|
||||
)
|
||||
|
||||
type ServeFunc[RQB RequestBuilder, RSB ResponseBuilder] func(req *Request[RQB], res *Response[RSB]) (err Error)
|
||||
type ServeFunc[RQB RequestBuilder, RSB ResponseBuilder] func(req *Request[RQB], rsb RSB) (err Error)
|
||||
|
||||
type server[RQB RequestBuilder, RSB ResponseBuilder] struct {
|
||||
logger log.Logger
|
||||
@ -161,7 +161,10 @@ func (srv *server[RQB, RSB]) PostServe(serve ServeFunc[RQB, RSB]) *server[RQB, R
|
||||
}
|
||||
|
||||
func (srv *server[RQB, RSB]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
rqb := NewRequestBuilder[RQB]()
|
||||
var (
|
||||
rqb = NewRequestBuilder[RQB]()
|
||||
rsb = NewResponseBuilder[RSB]()
|
||||
)
|
||||
wr := writer{ResponseWriter: w, Logger: srv.logger}
|
||||
if ok := wr.handleError(rqb.SetAllowed(r.Method)); !ok {
|
||||
return
|
||||
@ -180,15 +183,15 @@ func (srv *server[RQB, RSB]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
req := NewRequest(rqb)
|
||||
res := NewResponse(NewResponseBuilder[RSB]())
|
||||
for _, stage := range srv.serve {
|
||||
for _, serve := range stage {
|
||||
err := serve(req, res)
|
||||
err := serve(req, rsb)
|
||||
if ok := wr.handleError(err); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
res := NewResponse(rsb)
|
||||
if res.Header != nil {
|
||||
for key, value := range res.Header {
|
||||
for _, v := range value {
|
||||
|
Loading…
Reference in New Issue
Block a user