9edf3143 by astaxie

fix autorouter params

1 parent 00065f2b
...@@ -634,6 +634,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -634,6 +634,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
634 runrouter = controllerType 634 runrouter = controllerType
635 runMethod = mName 635 runMethod = mName
636 findrouter = true 636 findrouter = true
637 //parse params
638 otherurl := requestPath[len("/"+cName+"/"+strings.ToLower(mName)):]
639 if len(otherurl) > 1 {
640 plist := strings.Split(otherurl, "/")
641 for k, v := range plist[1:] {
642 context.Input.Params[strconv.Itoa(k)] = v
643 }
644 }
637 break 645 break
638 } 646 }
639 } 647 }
......
...@@ -19,6 +19,10 @@ func (this *TestController) List() { ...@@ -19,6 +19,10 @@ func (this *TestController) List() {
19 this.Ctx.Output.Body([]byte("i am list")) 19 this.Ctx.Output.Body([]byte("i am list"))
20 } 20 }
21 21
22 func (this *TestController) Params() {
23 this.Ctx.Output.Body([]byte(this.Ctx.Input.Params["0"] + this.Ctx.Input.Params["1"] + this.Ctx.Input.Params["2"]))
24 }
25
22 func (this *TestController) Myext() { 26 func (this *TestController) Myext() {
23 this.Ctx.Output.Body([]byte(this.Ctx.Input.Param(":ext"))) 27 this.Ctx.Output.Body([]byte(this.Ctx.Input.Param(":ext")))
24 } 28 }
...@@ -89,6 +93,18 @@ func TestAutoFunc(t *testing.T) { ...@@ -89,6 +93,18 @@ func TestAutoFunc(t *testing.T) {
89 } 93 }
90 } 94 }
91 95
96 func TestAutoFuncParams(t *testing.T) {
97 r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil)
98 w := httptest.NewRecorder()
99
100 handler := NewControllerRegistor()
101 handler.AddAuto(&TestController{})
102 handler.ServeHTTP(w, r)
103 if w.Body.String() != "20091112" {
104 t.Errorf("user define func can't run")
105 }
106 }
107
92 func TestAutoExtFunc(t *testing.T) { 108 func TestAutoExtFunc(t *testing.T) {
93 r, _ := http.NewRequest("GET", "/test/myext.json", nil) 109 r, _ := http.NewRequest("GET", "/test/myext.json", nil)
94 w := httptest.NewRecorder() 110 w := httptest.NewRecorder()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!