mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
add RouterMiddlewares to iris guide
This commit is contained in:
parent
1efbcabfce
commit
45aa45237c
|
@ -247,6 +247,8 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
Step5 interface {
|
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 registers one or more handlers to run before the requested route's handler.
|
||||||
Middlewares(handlers ...Handler) Step6
|
Middlewares(handlers ...Handler) Step6
|
||||||
}
|
}
|
||||||
|
@ -338,7 +340,13 @@ func (s *step4) Timeout(requestResponseLife, read, write time.Duration) Step5 {
|
||||||
type step5 struct {
|
type step5 struct {
|
||||||
step4 *step4
|
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 {
|
func (s *step5) Middlewares(handlers ...Handler) Step6 {
|
||||||
|
@ -426,6 +434,10 @@ func (s *step7) Build() *Application {
|
||||||
|
|
||||||
app.UseRouter(recover.New())
|
app.UseRouter(recover.New())
|
||||||
|
|
||||||
|
for _, routerLevelMiddleware := range s.step6.step5.routerMiddlewares {
|
||||||
|
app.UseRouter(routerLevelMiddleware)
|
||||||
|
}
|
||||||
|
|
||||||
app.UseRouter(func(ctx Context) {
|
app.UseRouter(func(ctx Context) {
|
||||||
ctx.Header("Server", "Iris")
|
ctx.Header("Server", "Iris")
|
||||||
if dev := s.step6.step5.step4.step3.developer; dev != "" {
|
if dev := s.step6.step5.step4.step3.developer; dev != "" {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// It accepts the controller ptr to a struct value,
|
// It accepts the controller ptr to a struct value,
|
||||||
// the gRPCServer itself, and a strict option which is explained below.
|
// 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),
|
// HTTP verb: only POST (Party.AllowMethods can be used for more),
|
||||||
// method parsing is disabled: path is the function name as it is,
|
// 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
|
// 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"
|
route.Description += " " + bckp // e.g. "gRPC controller"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user