mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
66209cae4f
Former-commit-id: 592e9cddf3511fc08e87f19ad39fdaac479b453f
45 lines
728 B
Go
45 lines
728 B
Go
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)
|
|
},
|
|
},
|
|
}
|
|
}
|