1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 11:57:02 +00:00
Former-commit-id: 592e9cddf3511fc08e87f19ad39fdaac479b453f
This commit is contained in:
Frédéric Meyer
2018-02-21 08:18:53 +03:00
parent c0e0886cb9
commit 66209cae4f
6 changed files with 81 additions and 7 deletions

View File

@@ -90,6 +90,8 @@ type APIBuilder struct {
doneHandlers context.Handlers
// global done handlers, order doesn't matter
doneGlobalHandlers context.Handlers
// fallback stack, LIFO order
fallbackStack *FallbackStack
// the per-party
relativePath string
}
@@ -106,6 +108,7 @@ func NewAPIBuilder() *APIBuilder {
reporter: errors.NewReporter(),
relativePath: "/",
routes: new(repository),
fallbackStack: NewFallbackStack(),
}
return api
@@ -268,9 +271,10 @@ func (api *APIBuilder) Party(relativePath string, handlers ...context.Handler) P
doneGlobalHandlers: api.doneGlobalHandlers,
reporter: api.reporter,
// per-party/children
middleware: middleware,
doneHandlers: api.doneHandlers,
relativePath: fullpath,
middleware: middleware,
doneHandlers: api.doneHandlers,
fallbackStack: api.fallbackStack,
relativePath: fullpath,
}
}
@@ -422,6 +426,15 @@ func (api *APIBuilder) DoneGlobal(handlers ...context.Handler) {
api.doneGlobalHandlers = append(api.doneGlobalHandlers, handlers...)
}
// Fallback appends Handler(s) to the current Party's fallback stack.
// Handler(s) is(are) called from Fallback stack when no route found and before sending NotFound status.
// Therefore Handler(s) in Fallback stack could send another thing than NotFound status,
// if `Context.Next()` method is not called.
// Done & DoneGlobal Handlers are not called.
func (api *APIBuilder) Fallback(middleware ...context.Handler) {
api.fallbackStack.add(middleware)
}
// Reset removes all the begin and done handlers that may derived from the parent party via `Use` & `Done`,
// note that the `Reset` will not reset the handlers that are registered via `UseGlobal` & `DoneGlobal`.
//