mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
new feature: versioned controllers
Former-commit-id: c797e23c78b1e74bbe9ba56673f3a98f17f5e2f7
This commit is contained in:
@@ -78,6 +78,12 @@ type ControllerActivator struct {
|
||||
// End-devs can change some properties of the *Route on the `BeforeActivator` by using the
|
||||
// `GetRoute/GetRoutes(functionName)`.
|
||||
routes map[string][]*router.Route
|
||||
// BeginHandlers is a slice of middleware for this controller.
|
||||
// These handlers will be prependend to each one of
|
||||
// the route that this controller will register(Handle/HandleMany/struct methods)
|
||||
// to the targeted Party.
|
||||
// Look the `Use` method too.
|
||||
BeginHandlers context.Handlers
|
||||
|
||||
// true if this controller listens and serves to websocket events.
|
||||
servesWebsocket bool
|
||||
@@ -199,6 +205,15 @@ func (c *ControllerActivator) GetRoutes(methodName string) []*router.Route {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Use registers a middleware for this Controller.
|
||||
// It appends one or more handlers to the `BeginHandlers`.
|
||||
// It's like the `Party.Use` but specifically
|
||||
// for the routes that this controller will register to the targeted `Party`.
|
||||
func (c *ControllerActivator) Use(handlers ...context.Handler) *ControllerActivator {
|
||||
c.BeginHandlers = append(c.BeginHandlers, handlers...)
|
||||
return c
|
||||
}
|
||||
|
||||
// Singleton returns new if all incoming clients' requests
|
||||
// have the same controller instance.
|
||||
// This is done automatically by iris to reduce the creation
|
||||
@@ -343,6 +358,7 @@ func (c *ControllerActivator) handleMany(method, path, funcName string, override
|
||||
}
|
||||
|
||||
handler := c.handlerOf(path, funcName)
|
||||
middleware = context.JoinHandlers(c.BeginHandlers, middleware)
|
||||
|
||||
// register the handler now.
|
||||
routes := c.app.Router.HandleMany(method, path, append(middleware, handler)...)
|
||||
|
||||
Reference in New Issue
Block a user