diff --git a/iris_guide.go b/iris_guide.go index d6d43d8c..f245bb55 100644 --- a/iris_guide.go +++ b/iris_guide.go @@ -247,6 +247,8 @@ type ( } Step5 interface { + // RouterMiddlewares registers one or more handlers to run before everything else. + RouterMiddlewares(handlers ...Handler) Step5 // Middlewares registers one or more handlers to run before the requested route's handler. Middlewares(handlers ...Handler) Step6 } @@ -338,7 +340,13 @@ func (s *step4) Timeout(requestResponseLife, read, write time.Duration) Step5 { type step5 struct { step4 *step4 - middlewares []Handler + routerMiddlewares []Handler // top-level router middlewares, fire even on 404s. + middlewares []Handler +} + +func (s *step5) RouterMiddlewares(handlers ...Handler) Step5 { + s.routerMiddlewares = append(s.routerMiddlewares, handlers...) + return s } func (s *step5) Middlewares(handlers ...Handler) Step6 { @@ -426,6 +434,10 @@ func (s *step7) Build() *Application { app.UseRouter(recover.New()) + for _, routerLevelMiddleware := range s.step6.step5.routerMiddlewares { + app.UseRouter(routerLevelMiddleware) + } + app.UseRouter(func(ctx Context) { ctx.Header("Server", "Iris") if dev := s.step6.step5.step4.step3.developer; dev != "" { diff --git a/mvc/grpc.go b/mvc/grpc.go index 34f9c87b..b8ef14bf 100644 --- a/mvc/grpc.go +++ b/mvc/grpc.go @@ -11,7 +11,7 @@ import ( // It accepts the controller ptr to a struct value, // the gRPCServer itself, and a strict option which is explained below. // -// The differences by a common controller are: +// The differences between an GRPC-based controller and a common one are: // HTTP verb: only POST (Party.AllowMethods can be used for more), // method parsing is disabled: path is the function name as it is, // if 'strictMode' option is true then this controller will only serve gRPC-based clients @@ -71,6 +71,5 @@ func (g GRPC) Apply(c *ControllerActivator) { } route.Description += " " + bckp // e.g. "gRPC controller" } - } }