5588bfc3 by asta.xie

support filter to get router. get runController & runMethod

1 parent 2f4acf46
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
4 "bytes" 4 "bytes"
5 "io/ioutil" 5 "io/ioutil"
6 "net/http" 6 "net/http"
7 "reflect"
7 "strconv" 8 "strconv"
8 "strings" 9 "strings"
9 10
...@@ -18,6 +19,8 @@ type BeegoInput struct { ...@@ -18,6 +19,8 @@ type BeegoInput struct {
18 Data map[interface{}]interface{} // store some values in this context when calling context in filter or controller. 19 Data map[interface{}]interface{} // store some values in this context when calling context in filter or controller.
19 Request *http.Request 20 Request *http.Request
20 RequestBody []byte 21 RequestBody []byte
22 RunController reflect.Type
23 RunMethod string
21 } 24 }
22 25
23 // NewInput return BeegoInput generated by http.Request. 26 // NewInput return BeegoInput generated by http.Request.
......
...@@ -626,7 +626,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -626,7 +626,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
626 context.Input.Body() 626 context.Input.Body()
627 } 627 }
628 628
629 if context.Input.RunController != nil && context.Input.RunMethod {
630 findrouter = true
631 runMethod = context.Input.RunMethod
632 runrouter = context.Input.RunController
633 }
634
629 //first find path from the fixrouters to Improve Performance 635 //first find path from the fixrouters to Improve Performance
636 if !findrouter {
630 for _, route := range p.fixrouters { 637 for _, route := range p.fixrouters {
631 n := len(requestPath) 638 n := len(requestPath)
632 if requestPath == route.pattern { 639 if requestPath == route.pattern {
...@@ -652,6 +659,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -652,6 +659,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
652 } 659 }
653 } 660 }
654 } 661 }
662 }
655 663
656 //find regex's router 664 //find regex's router
657 if !findrouter { 665 if !findrouter {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!