fix autorouter params
Showing
2 changed files
with
24 additions
and
0 deletions
| ... | @@ -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() | ... | ... |
-
Please register or sign in to post a comment