mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 11:57:02 +00:00
Save
Former-commit-id: 592e9cddf3511fc08e87f19ad39fdaac479b453f
This commit is contained in:
@@ -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`.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user