From 9b1978a863ed15cf7a6a78324674379454796571 Mon Sep 17 00:00:00 2001 From: some Date: Wed, 9 Oct 2024 11:40:28 -0400 Subject: [PATCH] Simplify NewServer, add server SetLogger method --- server.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 57fb453..92ebda7 100644 --- a/server.go +++ b/server.go @@ -23,14 +23,17 @@ type server struct { serve [numStages][]ServeFunc } -func NewServer[RB RequestBuilder, R Response](requestBuilder RB, response R, logger log.Logger, serve func(RB) (R, ErrorResponse)) (srv *server) { +func NewServer[RB RequestBuilder, R Response](serve func(RB) (R, ErrorResponse)) (srv *server) { + var ( + requestBuilder RB + response R + ) srv = &server{ prototype: Prototype{ PrototypeRequestBuilder: requestBuilder.Prototype(), PrototypeResponse: response.Prototype(), }, - logger: logger, - serve: [numStages][]ServeFunc{}, + serve: [numStages][]ServeFunc{}, } srv.serve[main] = append(srv.serve[main], func(req RequestBuilder, res Response) (errRes ErrorResponse) { res, errRes = serve(req.(RB)) @@ -39,6 +42,11 @@ func NewServer[RB RequestBuilder, R Response](requestBuilder RB, response R, log return srv } +func (srv *server) SetLogger(logger log.Logger) *server { + srv.logger = logger + return srv +} + func (srv *server) addServeFunc(when stage, serve ServeFunc) *server { if srv.serve[when] == nil { srv.serve[when] = make([]ServeFunc, 0)