Simplify NewServer, add server SetLogger method
This commit is contained in:
parent
3c64d0b477
commit
9b1978a863
14
server.go
14
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)
|
||||
|
Loading…
Reference in New Issue
Block a user