diff --git a/prototype.go b/prototype.go index 798e012..3692ce3 100644 --- a/prototype.go +++ b/prototype.go @@ -3,6 +3,7 @@ package router import "io" type RequestBuilder interface { + Prototype() (req PrototypeRequestBuilder) Allowed(method string) (errRes ErrorResponse) Header(header Header) (errRes ErrorResponse) ReadBody(body io.ReadCloser) (errRes ErrorResponse) @@ -14,6 +15,7 @@ type PrototypeRequestBuilder interface { } type Response interface { + Prototype() (req PrototypeResponse) Header() (header Header) BodyBytes() (body []byte) } diff --git a/server.go b/server.go index 602cf98..57fb453 100644 --- a/server.go +++ b/server.go @@ -23,13 +23,19 @@ type server struct { serve [numStages][]ServeFunc } -func NewServer(prototype Prototype, logger log.Logger, serve ServeFunc) (srv *server) { +func NewServer[RB RequestBuilder, R Response](requestBuilder RB, response R, logger log.Logger, serve func(RB) (R, ErrorResponse)) (srv *server) { srv = &server{ - prototype: prototype, - logger: logger, - serve: [numStages][]ServeFunc{}, + prototype: Prototype{ + PrototypeRequestBuilder: requestBuilder.Prototype(), + PrototypeResponse: response.Prototype(), + }, + logger: logger, + serve: [numStages][]ServeFunc{}, } - srv.serve[main] = append(srv.serve[main], serve) + srv.serve[main] = append(srv.serve[main], func(req RequestBuilder, res Response) (errRes ErrorResponse) { + res, errRes = serve(req.(RB)) + return + }) return srv }