iris/core/router/fallback_stack.go
Frédéric Meyer 66209cae4f Save
Former-commit-id: 592e9cddf3511fc08e87f19ad39fdaac479b453f
2018-02-21 08:18:53 +03:00

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)
},
},
}
}