mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:00:54 +00:00
fix autorouter params
This commit is contained in:
parent
00065f2b08
commit
9edf3143e1
@ -634,6 +634,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
runrouter = controllerType
|
runrouter = controllerType
|
||||||
runMethod = mName
|
runMethod = mName
|
||||||
findrouter = true
|
findrouter = true
|
||||||
|
//parse params
|
||||||
|
otherurl := requestPath[len("/"+cName+"/"+strings.ToLower(mName)):]
|
||||||
|
if len(otherurl) > 1 {
|
||||||
|
plist := strings.Split(otherurl, "/")
|
||||||
|
for k, v := range plist[1:] {
|
||||||
|
context.Input.Params[strconv.Itoa(k)] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,10 @@ func (this *TestController) List() {
|
|||||||
this.Ctx.Output.Body([]byte("i am list"))
|
this.Ctx.Output.Body([]byte("i am list"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *TestController) Params() {
|
||||||
|
this.Ctx.Output.Body([]byte(this.Ctx.Input.Params["0"] + this.Ctx.Input.Params["1"] + this.Ctx.Input.Params["2"]))
|
||||||
|
}
|
||||||
|
|
||||||
func (this *TestController) Myext() {
|
func (this *TestController) Myext() {
|
||||||
this.Ctx.Output.Body([]byte(this.Ctx.Input.Param(":ext")))
|
this.Ctx.Output.Body([]byte(this.Ctx.Input.Param(":ext")))
|
||||||
}
|
}
|
||||||
@ -89,6 +93,18 @@ func TestAutoFunc(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAutoFuncParams(t *testing.T) {
|
||||||
|
r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler := NewControllerRegistor()
|
||||||
|
handler.AddAuto(&TestController{})
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
if w.Body.String() != "20091112" {
|
||||||
|
t.Errorf("user define func can't run")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAutoExtFunc(t *testing.T) {
|
func TestAutoExtFunc(t *testing.T) {
|
||||||
r, _ := http.NewRequest("GET", "/test/myext.json", nil)
|
r, _ := http.NewRequest("GET", "/test/myext.json", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
Loading…
Reference in New Issue
Block a user