diff --git a/server.go b/server.go index f910647..d02f1a2 100644 --- a/server.go +++ b/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 {