mirror of
https://github.com/astaxie/beego.git
synced 2025-07-03 17:20:18 +00:00
Changes to handle multi filters on execution pt
This commit is contained in:
11
router.go
11
router.go
@ -381,7 +381,9 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface)
|
||||
}
|
||||
|
||||
// Add a FilterFunc with pattern rule and action constant.
|
||||
func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter FilterFunc) error {
|
||||
// The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
|
||||
func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error {
|
||||
|
||||
mr := new(FilterRouter)
|
||||
mr.tree = NewTree()
|
||||
mr.pattern = pattern
|
||||
@ -389,6 +391,11 @@ func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter Filter
|
||||
if !RouterCaseSensitive {
|
||||
pattern = strings.ToLower(pattern)
|
||||
}
|
||||
if params == nil {
|
||||
mr.returnOnOutput = true
|
||||
} else {
|
||||
mr.returnOnOutput = params[0]
|
||||
}
|
||||
mr.tree.AddRouter(pattern, true)
|
||||
return p.insertFilterRouter(pos, mr)
|
||||
}
|
||||
@ -587,7 +594,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||
if ok, p := filterR.ValidRouter(urlPath); ok {
|
||||
context.Input.Params = p
|
||||
filterR.filterFunc(context)
|
||||
if w.started {
|
||||
if filterR.returnOnOutput && w.started {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user