mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
Save
Former-commit-id: 592e9cddf3511fc08e87f19ad39fdaac479b453f
This commit is contained in:
44
core/router/fallback_stack.go
Normal file
44
core/router/fallback_stack.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
type FallbackStack struct {
|
||||
handlers context.Handlers
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
func (stk *FallbackStack) add(h context.Handlers) {
|
||||
stk.m.Lock()
|
||||
defer stk.m.Unlock()
|
||||
|
||||
stk.handlers = append(stk.handlers, h...)
|
||||
|
||||
copy(stk.handlers[len(h):], stk.handlers)
|
||||
copy(stk.handlers, h)
|
||||
}
|
||||
|
||||
func (stk *FallbackStack) list() context.Handlers {
|
||||
res := make(context.Handlers, len(stk.handlers))
|
||||
|
||||
stk.m.Lock()
|
||||
defer stk.m.Unlock()
|
||||
|
||||
copy(res, stk.handlers)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func NewFallbackStack() *FallbackStack {
|
||||
return &FallbackStack{
|
||||
handlers: context.Handlers{
|
||||
func(ctx context.Context) {
|
||||
ctx.StatusCode(http.StatusNotFound)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user