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:
parent
2f4acf46c6
commit
5588bfc35e
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -13,11 +14,13 @@ import (
|
|||||||
// BeegoInput operates the http request header ,data ,cookie and body.
|
// BeegoInput operates the http request header ,data ,cookie and body.
|
||||||
// it also contains router params and current session.
|
// it also contains router params and current session.
|
||||||
type BeegoInput struct {
|
type BeegoInput struct {
|
||||||
CruSession session.SessionStore
|
CruSession session.SessionStore
|
||||||
Params map[string]string
|
Params map[string]string
|
||||||
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.
|
||||||
|
50
router.go
50
router.go
@ -626,29 +626,37 @@ 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
|
||||||
for _, route := range p.fixrouters {
|
if !findrouter {
|
||||||
n := len(requestPath)
|
for _, route := range p.fixrouters {
|
||||||
if requestPath == route.pattern {
|
n := len(requestPath)
|
||||||
runMethod = p.getRunMethod(r.Method, context, route)
|
if requestPath == route.pattern {
|
||||||
if runMethod != "" {
|
runMethod = p.getRunMethod(r.Method, context, route)
|
||||||
runrouter = route.controllerType
|
if runMethod != "" {
|
||||||
findrouter = true
|
runrouter = route.controllerType
|
||||||
break
|
findrouter = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// pattern /admin url /admin 200 /admin/ 200
|
||||||
// pattern /admin url /admin 200 /admin/ 200
|
// pattern /admin/ url /admin 301 /admin/ 200
|
||||||
// pattern /admin/ url /admin 301 /admin/ 200
|
if requestPath[n-1] != '/' && requestPath+"/" == route.pattern {
|
||||||
if requestPath[n-1] != '/' && requestPath+"/" == route.pattern {
|
http.Redirect(w, r, requestPath+"/", 301)
|
||||||
http.Redirect(w, r, requestPath+"/", 301)
|
goto Admin
|
||||||
goto Admin
|
}
|
||||||
}
|
if requestPath[n-1] == '/' && route.pattern+"/" == requestPath {
|
||||||
if requestPath[n-1] == '/' && route.pattern+"/" == requestPath {
|
runMethod = p.getRunMethod(r.Method, context, route)
|
||||||
runMethod = p.getRunMethod(r.Method, context, route)
|
if runMethod != "" {
|
||||||
if runMethod != "" {
|
runrouter = route.controllerType
|
||||||
runrouter = route.controllerType
|
findrouter = true
|
||||||
findrouter = true
|
break
|
||||||
break
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user