Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions transport/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func MethodNotAllowedHandler(handler http.Handler) ServerOption {
}
}

func RouterMiddleware(middlewareFunc mux.MiddlewareFunc) ServerOption {
return func(s *Server) {
s.routerMiddleware = append(s.routerMiddleware, middlewareFunc)
}
}

// Server is an HTTP server wrapper.
type Server struct {
*http.Server
Expand All @@ -172,6 +178,7 @@ type Server struct {
ene EncodeErrorFunc
strictSlash bool
router *mux.Router
routerMiddleware []mux.MiddlewareFunc
}

// NewServer creates an HTTP server by options.
Expand All @@ -196,6 +203,7 @@ func NewServer(opts ...ServerOption) *Server {
}
srv.router.StrictSlash(srv.strictSlash)
srv.router.Use(srv.filter())
srv.router.Use(srv.routerMiddleware...)
srv.Server = &http.Server{
Handler: FilterChain(srv.filters...)(srv.router),
TLSConfig: srv.tlsConf,
Expand Down