create a separate handler on webServer so type assertion works in tests
This commit is contained in:
parent
37e01449e0
commit
5d7cb2c1a2
1 changed files with 4 additions and 2 deletions
|
@ -38,8 +38,9 @@ func RegisterServer(server Server, endpoints Endpoints, options ...ServerOption)
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.createRouter()
|
ws.createRouter()
|
||||||
|
ws.handler = ws.router
|
||||||
if ws.corsOpts != nil {
|
if ws.corsOpts != nil {
|
||||||
return cors.New(*ws.corsOpts).Handler(ws)
|
ws.handler = cors.New(*ws.corsOpts).Handler(ws.router)
|
||||||
}
|
}
|
||||||
return ws
|
return ws
|
||||||
}
|
}
|
||||||
|
@ -88,6 +89,7 @@ func WithFallbackLogger(logger *slog.Logger) ServerOption {
|
||||||
type webServer struct {
|
type webServer struct {
|
||||||
server Server
|
server Server
|
||||||
router *chi.Mux
|
router *chi.Mux
|
||||||
|
handler http.Handler
|
||||||
endpoints Endpoints
|
endpoints Endpoints
|
||||||
decoder httphelper.Decoder
|
decoder httphelper.Decoder
|
||||||
corsOpts *cors.Options
|
corsOpts *cors.Options
|
||||||
|
@ -95,7 +97,7 @@ type webServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
s.router.ServeHTTP(w, r)
|
s.handler.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *webServer) getLogger(ctx context.Context) *slog.Logger {
|
func (s *webServer) getLogger(ctx context.Context) *slog.Logger {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue