mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:10:55 +00:00
beego: modify the filter sequence
This commit is contained in:
parent
2570f075d9
commit
f7b01aab13
@ -82,7 +82,7 @@ type ControllerInterface interface {
|
|||||||
Render() error
|
Render() error
|
||||||
XsrfToken() string
|
XsrfToken() string
|
||||||
CheckXsrfCookie() bool
|
CheckXsrfCookie() bool
|
||||||
HandlerFunc(fn string)
|
HandlerFunc(fn string) bool
|
||||||
URLMapping()
|
URLMapping()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,11 +147,12 @@ func (c *Controller) Options() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// call function fn
|
// call function fn
|
||||||
func (c *Controller) HandlerFunc(fnname string) {
|
func (c *Controller) HandlerFunc(fnname string) bool {
|
||||||
if v, ok := c.methodMapping[fnname]; ok {
|
if v, ok := c.methodMapping[fnname]; ok {
|
||||||
v()
|
v()
|
||||||
|
return true
|
||||||
} else {
|
} else {
|
||||||
Error("call funcname not exist in the methodMapping: " + fnname)
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
parser.go
18
parser.go
@ -98,11 +98,6 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
|
|||||||
func genRouterCode() {
|
func genRouterCode() {
|
||||||
os.Mkdir(path.Join(AppPath, "routers"), 0755)
|
os.Mkdir(path.Join(AppPath, "routers"), 0755)
|
||||||
Info("generate router from comments")
|
Info("generate router from comments")
|
||||||
f, err := os.Create(path.Join(AppPath, "routers", "commentsRouter.go"))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
var globalinfo string
|
var globalinfo string
|
||||||
for k, cList := range genInfoList {
|
for k, cList := range genInfoList {
|
||||||
for _, c := range cList {
|
for _, c := range cList {
|
||||||
@ -124,9 +119,16 @@ func genRouterCode() {
|
|||||||
}
|
}
|
||||||
params = strings.TrimRight(params, ",") + "}"
|
params = strings.TrimRight(params, ",") + "}"
|
||||||
}
|
}
|
||||||
globalinfo = globalinfo + fmt.Sprintln(`beego.GlobalControllerRouter["`+k+`"] = &beego.ControllerComments{"`+
|
globalinfo = globalinfo + fmt.Sprintln(`beego.GlobalControllerRouter["`+k+`"] = append(beego.GlobalControllerRouter["`+k+`"], beego.ControllerComments{"`+
|
||||||
strings.TrimSpace(c.Method)+`", "`+c.Router+`", `+allmethod+", "+params+"}")
|
strings.TrimSpace(c.Method)+`", "`+c.Router+`", `+allmethod+", "+params+"})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.WriteString(strings.Replace(globalRouterTemplate, "{{.globalinfo}}", globalinfo, -1))
|
if globalinfo != "" {
|
||||||
|
f, err := os.Create(path.Join(AppPath, "routers", "commentsRouter.go"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
f.WriteString(strings.Replace(globalRouterTemplate, "{{.globalinfo}}", globalinfo, -1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
19
router.go
19
router.go
@ -559,10 +559,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
http.Error(w, "Method Not Allowed", 405)
|
http.Error(w, "Method Not Allowed", 405)
|
||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
//static file server
|
|
||||||
if serverStaticRouter(context) {
|
|
||||||
goto Admin
|
|
||||||
}
|
|
||||||
|
|
||||||
if !context.Input.IsGet() && !context.Input.IsHead() {
|
if !context.Input.IsGet() && !context.Input.IsHead() {
|
||||||
if CopyRequestBody && !context.Input.IsUpload() {
|
if CopyRequestBody && !context.Input.IsUpload() {
|
||||||
@ -575,6 +571,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//static file server
|
||||||
|
if serverStaticRouter(context) {
|
||||||
|
goto Admin
|
||||||
|
}
|
||||||
|
|
||||||
if context.Input.RunController != nil && context.Input.RunMethod != "" {
|
if context.Input.RunController != nil && context.Input.RunMethod != "" {
|
||||||
findrouter = true
|
findrouter = true
|
||||||
runMethod = context.Input.RunMethod
|
runMethod = context.Input.RunMethod
|
||||||
@ -666,6 +667,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
execController.URLMapping()
|
||||||
|
|
||||||
if !w.started {
|
if !w.started {
|
||||||
//exec main logic
|
//exec main logic
|
||||||
switch runMethod {
|
switch runMethod {
|
||||||
@ -684,9 +687,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
case "Options":
|
case "Options":
|
||||||
execController.Options()
|
execController.Options()
|
||||||
default:
|
default:
|
||||||
in := make([]reflect.Value, 0)
|
if !execController.HandlerFunc(runMethod) {
|
||||||
method := vc.MethodByName(runMethod)
|
in := make([]reflect.Value, 0)
|
||||||
method.Call(in)
|
method := vc.MethodByName(runMethod)
|
||||||
|
method.Call(in)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//render template
|
//render template
|
||||||
|
Loading…
Reference in New Issue
Block a user