1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00
Former-commit-id: d93af027428259c857c7a5ddf6e21cfd0b09b470
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-06-14 08:44:41 +03:00
parent ed5964716b
commit 4afef007a4
2 changed files with 31 additions and 2 deletions

View File

@@ -236,6 +236,18 @@ func (c *ControllerActivator) isReservedMethod(name string) bool {
return false
}
func (c *ControllerActivator) isReservedMethodHandler(method, path string) bool {
for _, routes := range c.routes {
for _, r := range routes {
if r.Method == method && r.Path == path {
return true
}
}
}
return false
}
func (c *ControllerActivator) markAsWebsocket() {
c.servesWebsocket = true
c.attachInjector()
@@ -296,8 +308,10 @@ func (c *ControllerActivator) addErr(err error) bool {
// Just like `Party#Handle`, it returns the `*router.Route`, if failed
// then it logs the errors and it returns nil, you can check the errors
// programmatically by the `Party#GetReporter`.
//
// Handle will add a route to the "funcName".
func (c *ControllerActivator) Handle(method, path, funcName string, middleware ...context.Handler) *router.Route {
routes := c.HandleMany(method, path, funcName, middleware...)
routes := c.handleMany(method, path, funcName, false, middleware...)
if len(routes) == 0 {
return nil
}
@@ -315,13 +329,14 @@ func (c *ControllerActivator) Handle(method, path, funcName string, middleware .
// func (*Controller) BeforeActivation(b mvc.BeforeActivation) {
// b.HandleMany("GET", "/path /path1" /path2", "HandlePath")
// }
// HandleMany will override any routes of this "funcName".
func (c *ControllerActivator) HandleMany(method, path, funcName string, middleware ...context.Handler) []*router.Route {
return c.handleMany(method, path, funcName, true, middleware...)
}
func (c *ControllerActivator) handleMany(method, path, funcName string, override bool, middleware ...context.Handler) []*router.Route {
if method == "" || path == "" || funcName == "" ||
c.isReservedMethod(funcName) {
(c.isReservedMethod(funcName) && c.isReservedMethodHandler(method, path)) {
// isReservedMethod -> if it's already registered
// by a previous Handle or analyze methods internally.
return nil