1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 09:20:55 +00:00

support filter to get router. get runController & runMethod

This commit is contained in:
asta.xie 2014-03-29 14:55:34 +08:00
parent 2f4acf46c6
commit 5588bfc35e
2 changed files with 37 additions and 26 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"reflect"
"strconv" "strconv"
"strings" "strings"
@ -18,6 +19,8 @@ type BeegoInput struct {
Data map[interface{}]interface{} // store some values in this context when calling context in filter or controller. Data map[interface{}]interface{} // store some values in this context when calling context in filter or controller.
Request *http.Request Request *http.Request
RequestBody []byte RequestBody []byte
RunController reflect.Type
RunMethod string
} }
// NewInput return BeegoInput generated by http.Request. // NewInput return BeegoInput generated by http.Request.

View File

@ -626,7 +626,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
context.Input.Body() context.Input.Body()
} }
if context.Input.RunController != nil && context.Input.RunMethod {
findrouter = true
runMethod = context.Input.RunMethod
runrouter = context.Input.RunController
}
//first find path from the fixrouters to Improve Performance //first find path from the fixrouters to Improve Performance
if !findrouter {
for _, route := range p.fixrouters { for _, route := range p.fixrouters {
n := len(requestPath) n := len(requestPath)
if requestPath == route.pattern { if requestPath == route.pattern {
@ -652,6 +659,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
} }
} }
} }
}
//find regex's router //find regex's router
if !findrouter { if !findrouter {