1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 02:47:04 +00:00

add RemoveHandler to Party too, as requested at #1658

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-10-12 12:56:54 +03:00
parent f6905a3f79
commit 546c7bf465
4 changed files with 58 additions and 15 deletions

View File

@@ -150,20 +150,22 @@ func (r *Route) UseOnce(handlers ...context.Handler) {
// Returns the total amount of handlers removed.
//
// Should be called before Application Build.
func (r *Route) RemoveHandler(nameOrHandler interface{}) (count int) {
handlerName := ""
switch h := nameOrHandler.(type) {
case string:
handlerName = h
case context.Handler:
handlerName = context.HandlerName(h)
default:
panic(fmt.Sprintf("remove handler: unexpected type of %T", h))
}
func (r *Route) RemoveHandler(namesOrHandlers ...interface{}) (count int) {
for _, nameOrHandler := range namesOrHandlers {
handlerName := ""
switch h := nameOrHandler.(type) {
case string:
handlerName = h
case context.Handler:
handlerName = context.HandlerName(h)
default:
panic(fmt.Sprintf("remove handler: unexpected type of %T", h))
}
r.beginHandlers = removeHandler(handlerName, r.beginHandlers, &count)
r.Handlers = removeHandler(handlerName, r.Handlers, &count)
r.doneHandlers = removeHandler(handlerName, r.doneHandlers, &count)
r.beginHandlers = removeHandler(handlerName, r.beginHandlers, &count)
r.Handlers = removeHandler(handlerName, r.Handlers, &count)
r.doneHandlers = removeHandler(handlerName, r.doneHandlers, &count)
}
return
}