f7b01aab by astaxie

beego: modify the filter sequence

1 parent 2570f075
...@@ -82,7 +82,7 @@ type ControllerInterface interface { ...@@ -82,7 +82,7 @@ type ControllerInterface interface {
82 Render() error 82 Render() error
83 XsrfToken() string 83 XsrfToken() string
84 CheckXsrfCookie() bool 84 CheckXsrfCookie() bool
85 HandlerFunc(fn string) 85 HandlerFunc(fn string) bool
86 URLMapping() 86 URLMapping()
87 } 87 }
88 88
...@@ -147,11 +147,12 @@ func (c *Controller) Options() { ...@@ -147,11 +147,12 @@ func (c *Controller) Options() {
147 } 147 }
148 148
149 // call function fn 149 // call function fn
150 func (c *Controller) HandlerFunc(fnname string) { 150 func (c *Controller) HandlerFunc(fnname string) bool {
151 if v, ok := c.methodMapping[fnname]; ok { 151 if v, ok := c.methodMapping[fnname]; ok {
152 v() 152 v()
153 return true
153 } else { 154 } else {
154 Error("call funcname not exist in the methodMapping: " + fnname) 155 return false
155 } 156 }
156 } 157 }
157 158
......
...@@ -98,11 +98,6 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat ...@@ -98,11 +98,6 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat
98 func genRouterCode() { 98 func genRouterCode() {
99 os.Mkdir(path.Join(AppPath, "routers"), 0755) 99 os.Mkdir(path.Join(AppPath, "routers"), 0755)
100 Info("generate router from comments") 100 Info("generate router from comments")
101 f, err := os.Create(path.Join(AppPath, "routers", "commentsRouter.go"))
102 if err != nil {
103 panic(err)
104 }
105 defer f.Close()
106 var globalinfo string 101 var globalinfo string
107 for k, cList := range genInfoList { 102 for k, cList := range genInfoList {
108 for _, c := range cList { 103 for _, c := range cList {
...@@ -124,9 +119,16 @@ func genRouterCode() { ...@@ -124,9 +119,16 @@ func genRouterCode() {
124 } 119 }
125 params = strings.TrimRight(params, ",") + "}" 120 params = strings.TrimRight(params, ",") + "}"
126 } 121 }
127 globalinfo = globalinfo + fmt.Sprintln(`beego.GlobalControllerRouter["`+k+`"] = &beego.ControllerComments{"`+ 122 globalinfo = globalinfo + fmt.Sprintln(`beego.GlobalControllerRouter["`+k+`"] = append(beego.GlobalControllerRouter["`+k+`"], beego.ControllerComments{"`+
128 strings.TrimSpace(c.Method)+`", "`+c.Router+`", `+allmethod+", "+params+"}") 123 strings.TrimSpace(c.Method)+`", "`+c.Router+`", `+allmethod+", "+params+"})")
129 } 124 }
130 } 125 }
126 if globalinfo != "" {
127 f, err := os.Create(path.Join(AppPath, "routers", "commentsRouter.go"))
128 if err != nil {
129 panic(err)
130 }
131 defer f.Close()
131 f.WriteString(strings.Replace(globalRouterTemplate, "{{.globalinfo}}", globalinfo, -1)) 132 f.WriteString(strings.Replace(globalRouterTemplate, "{{.globalinfo}}", globalinfo, -1))
133 }
132 } 134 }
......
...@@ -559,10 +559,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -559,10 +559,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
559 http.Error(w, "Method Not Allowed", 405) 559 http.Error(w, "Method Not Allowed", 405)
560 goto Admin 560 goto Admin
561 } 561 }
562 //static file server
563 if serverStaticRouter(context) {
564 goto Admin
565 }
566 562
567 if !context.Input.IsGet() && !context.Input.IsHead() { 563 if !context.Input.IsGet() && !context.Input.IsHead() {
568 if CopyRequestBody && !context.Input.IsUpload() { 564 if CopyRequestBody && !context.Input.IsUpload() {
...@@ -575,6 +571,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -575,6 +571,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
575 goto Admin 571 goto Admin
576 } 572 }
577 573
574 //static file server
575 if serverStaticRouter(context) {
576 goto Admin
577 }
578
578 if context.Input.RunController != nil && context.Input.RunMethod != "" { 579 if context.Input.RunController != nil && context.Input.RunMethod != "" {
579 findrouter = true 580 findrouter = true
580 runMethod = context.Input.RunMethod 581 runMethod = context.Input.RunMethod
...@@ -666,6 +667,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -666,6 +667,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
666 } 667 }
667 } 668 }
668 669
670 execController.URLMapping()
671
669 if !w.started { 672 if !w.started {
670 //exec main logic 673 //exec main logic
671 switch runMethod { 674 switch runMethod {
...@@ -684,10 +687,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -684,10 +687,12 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
684 case "Options": 687 case "Options":
685 execController.Options() 688 execController.Options()
686 default: 689 default:
690 if !execController.HandlerFunc(runMethod) {
687 in := make([]reflect.Value, 0) 691 in := make([]reflect.Value, 0)
688 method := vc.MethodByName(runMethod) 692 method := vc.MethodByName(runMethod)
689 method.Call(in) 693 method.Call(in)
690 } 694 }
695 }
691 696
692 //render template 697 //render template
693 if !w.started && !context.Input.IsWebsocket() { 698 if !w.started && !context.Input.IsWebsocket() {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!