beego:remove unused code
Showing
2 changed files
with
17 additions
and
27 deletions
| ... | @@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 797 | } | 797 | } |
| 798 | 798 | ||
| 799 | if len(route.params) > 0 { | 799 | if len(route.params) > 0 { |
| 800 | //add url parameters to the query param map | ||
| 801 | values := r.URL.Query() | ||
| 802 | for i, match := range matches[1:] { | 800 | for i, match := range matches[1:] { |
| 803 | values.Add(route.params[i], match) | ||
| 804 | params[route.params[i]] = match | 801 | params[route.params[i]] = match |
| 805 | } | 802 | } |
| 806 | //reassemble query params and add to RawQuery | ||
| 807 | r.URL.RawQuery = url.Values(values).Encode() | ||
| 808 | } | 803 | } |
| 809 | runMethod = p.getRunMethod(r.Method, context, route) | 804 | runMethod = p.getRunMethod(r.Method, context, route) |
| 810 | if runMethod != "" { | 805 | if runMethod != "" { | ... | ... |
| ... | @@ -43,6 +43,15 @@ func (this *TestController) GetUrl() { | ... | @@ -43,6 +43,15 @@ func (this *TestController) GetUrl() { |
| 43 | this.Ctx.Output.Body([]byte(this.UrlFor(".Myext"))) | 43 | this.Ctx.Output.Body([]byte(this.UrlFor(".Myext"))) |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | func (t *TestController) GetParams() { | ||
| 47 | t.Ctx.WriteString(t.Ctx.Input.Query(":last") + "+" + | ||
| 48 | t.Ctx.Input.Query(":first") + "+" + t.Ctx.Input.Query("learn")) | ||
| 49 | } | ||
| 50 | |||
| 51 | func (t *TestController) GetManyRouter() { | ||
| 52 | t.Ctx.WriteString(t.Ctx.Input.Query(":id") + t.Ctx.Input.Query(":page")) | ||
| 53 | } | ||
| 54 | |||
| 46 | type ResStatus struct { | 55 | type ResStatus struct { |
| 47 | Code int | 56 | Code int |
| 48 | Msg string | 57 | Msg string |
| ... | @@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) { | ... | @@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) { |
| 147 | w := httptest.NewRecorder() | 156 | w := httptest.NewRecorder() |
| 148 | 157 | ||
| 149 | handler := NewControllerRegistor() | 158 | handler := NewControllerRegistor() |
| 150 | handler.Add("/person/:last/:first", &TestController{}) | 159 | handler.Add("/person/:last/:first", &TestController{}, "get:GetParams") |
| 151 | handler.ServeHTTP(w, r) | 160 | handler.ServeHTTP(w, r) |
| 152 | 161 | body := w.Body.String() | |
| 153 | lastNameParam := r.URL.Query().Get(":last") | 162 | if body != "anderson+thomas+kungfu" { |
| 154 | firstNameParam := r.URL.Query().Get(":first") | 163 | t.Errorf("url param set to [%s];", body) |
| 155 | learnParam := r.URL.Query().Get("learn") | ||
| 156 | |||
| 157 | if lastNameParam != "anderson" { | ||
| 158 | t.Errorf("url param set to [%s]; want [%s]", lastNameParam, "anderson") | ||
| 159 | } | ||
| 160 | if firstNameParam != "thomas" { | ||
| 161 | t.Errorf("url param set to [%s]; want [%s]", firstNameParam, "thomas") | ||
| 162 | } | ||
| 163 | if learnParam != "kungfu" { | ||
| 164 | t.Errorf("url param set to [%s]; want [%s]", learnParam, "kungfu") | ||
| 165 | } | 164 | } |
| 166 | } | 165 | } |
| 167 | 166 | ||
| ... | @@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) { | ... | @@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) { |
| 171 | w := httptest.NewRecorder() | 170 | w := httptest.NewRecorder() |
| 172 | 171 | ||
| 173 | handler := NewControllerRegistor() | 172 | handler := NewControllerRegistor() |
| 174 | handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}) | 173 | handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}, "get:GetManyRouter") |
| 175 | handler.ServeHTTP(w, r) | 174 | handler.ServeHTTP(w, r) |
| 176 | 175 | ||
| 177 | id := r.URL.Query().Get(":id") | 176 | body := w.Body.String() |
| 178 | page := r.URL.Query().Get(":page") | ||
| 179 | 177 | ||
| 180 | if id != "32" { | 178 | if body != "3212" { |
| 181 | t.Errorf("url param set to [%s]; want [%s]", id, "32") | 179 | t.Errorf("url param set to [%s];", body) |
| 182 | } | ||
| 183 | if page != "12" { | ||
| 184 | t.Errorf("url param set to [%s]; want [%s]", page, "12") | ||
| 185 | } | 180 | } |
| 186 | } | 181 | } |
| 187 | 182 | ... | ... |
-
Please register or sign in to post a comment