mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 18:30:56 +00:00
beego:fix when user defined function equal to HTTP
This commit is contained in:
parent
aa275fb5ce
commit
c13141b8bf
13
router.go
13
router.go
@ -428,14 +428,13 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
if c.routerType == routerTypeBeego && c.controllerType.Name() == controllName {
|
if c.routerType == routerTypeBeego && c.controllerType.Name() == controllName {
|
||||||
find := false
|
find := false
|
||||||
if _, ok := HTTPMETHOD[strings.ToUpper(methodName)]; ok {
|
if _, ok := HTTPMETHOD[strings.ToUpper(methodName)]; ok {
|
||||||
if m, ok := c.methods[strings.ToUpper(methodName)]; ok && m != strings.ToUpper(methodName) {
|
if m, ok := c.methods[strings.ToUpper(methodName)]; ok && m == strings.ToUpper(methodName) {
|
||||||
return false, ""
|
find = true
|
||||||
} else if m, ok = c.methods["*"]; ok && m != methodName {
|
} else if m, ok = c.methods["*"]; ok && m == methodName {
|
||||||
return false, ""
|
|
||||||
} else {
|
|
||||||
find = true
|
find = true
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
if !find {
|
||||||
for _, md := range c.methods {
|
for _, md := range c.methods {
|
||||||
if md == methodName {
|
if md == methodName {
|
||||||
find = true
|
find = true
|
||||||
@ -507,6 +506,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
return true, url
|
return true, url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return false, ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,10 @@ func (this *TestController) Post() {
|
|||||||
this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name")))
|
this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *TestController) Param() {
|
||||||
|
this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name")))
|
||||||
|
}
|
||||||
|
|
||||||
func (this *TestController) List() {
|
func (this *TestController) List() {
|
||||||
this.Ctx.Output.Body([]byte("i am list"))
|
this.Ctx.Output.Body([]byte("i am list"))
|
||||||
}
|
}
|
||||||
@ -74,14 +78,14 @@ func (this *JsonController) Get() {
|
|||||||
func TestUrlFor(t *testing.T) {
|
func TestUrlFor(t *testing.T) {
|
||||||
handler := NewControllerRegister()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/api/list", &TestController{}, "*:List")
|
handler.Add("/api/list", &TestController{}, "*:List")
|
||||||
handler.Add("/person/:last/:first", &TestController{})
|
handler.Add("/person/:last/:first", &TestController{}, "*:Param")
|
||||||
handler.AddAuto(&TestController{})
|
handler.AddAuto(&TestController{})
|
||||||
if handler.UrlFor("TestController.List") != "/api/list" {
|
if handler.UrlFor("TestController.List") != "/api/list" {
|
||||||
Info(handler.UrlFor("TestController.List"))
|
Info(handler.UrlFor("TestController.List"))
|
||||||
t.Errorf("TestController.List must equal to /api/list")
|
t.Errorf("TestController.List must equal to /api/list")
|
||||||
}
|
}
|
||||||
if handler.UrlFor("TestController.Get", ":last", "xie", ":first", "asta") != "/person/xie/asta" {
|
if handler.UrlFor("TestController.Param", ":last", "xie", ":first", "asta") != "/person/xie/asta" {
|
||||||
t.Errorf("TestController.Get must equal to /person/xie/asta")
|
t.Errorf("TestController.Param must equal to /person/xie/asta, but get " + handler.UrlFor("TestController.Param", ":last", "xie", ":first", "asta"))
|
||||||
}
|
}
|
||||||
if handler.UrlFor("TestController.Myext") != "/test/myext" {
|
if handler.UrlFor("TestController.Myext") != "/test/myext" {
|
||||||
t.Errorf("TestController.Myext must equal to /test/myext")
|
t.Errorf("TestController.Myext must equal to /test/myext")
|
||||||
|
Loading…
Reference in New Issue
Block a user