c13141b8 by astaxie

beego:fix when user defined function equal to HTTP

1 parent aa275fb5
...@@ -428,14 +428,13 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin ...@@ -428,14 +428,13 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
428 if c.routerType == routerTypeBeego && c.controllerType.Name() == controllName { 428 if c.routerType == routerTypeBeego && c.controllerType.Name() == controllName {
429 find := false 429 find := false
430 if _, ok := HTTPMETHOD[strings.ToUpper(methodName)]; ok { 430 if _, ok := HTTPMETHOD[strings.ToUpper(methodName)]; ok {
431 if m, ok := c.methods[strings.ToUpper(methodName)]; ok && m != strings.ToUpper(methodName) { 431 if m, ok := c.methods[strings.ToUpper(methodName)]; ok && m == strings.ToUpper(methodName) {
432 return false, "" 432 find = true
433 } else if m, ok = c.methods["*"]; ok && m != methodName { 433 } else if m, ok = c.methods["*"]; ok && m == methodName {
434 return false, ""
435 } else {
436 find = true 434 find = true
437 } 435 }
438 } else { 436 }
437 if !find {
439 for _, md := range c.methods { 438 for _, md := range c.methods {
440 if md == methodName { 439 if md == methodName {
441 find = true 440 find = true
...@@ -507,6 +506,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin ...@@ -507,6 +506,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
507 return true, url 506 return true, url
508 } 507 }
509 } 508 }
509 } else {
510 return false, ""
510 } 511 }
511 } 512 }
512 } 513 }
......
...@@ -27,6 +27,10 @@ func (this *TestController) Post() { ...@@ -27,6 +27,10 @@ func (this *TestController) Post() {
27 this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name"))) 27 this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name")))
28 } 28 }
29 29
30 func (this *TestController) Param() {
31 this.Ctx.Output.Body([]byte(this.Ctx.Input.Query(":name")))
32 }
33
30 func (this *TestController) List() { 34 func (this *TestController) List() {
31 this.Ctx.Output.Body([]byte("i am list")) 35 this.Ctx.Output.Body([]byte("i am list"))
32 } 36 }
...@@ -74,14 +78,14 @@ func (this *JsonController) Get() { ...@@ -74,14 +78,14 @@ func (this *JsonController) Get() {
74 func TestUrlFor(t *testing.T) { 78 func TestUrlFor(t *testing.T) {
75 handler := NewControllerRegister() 79 handler := NewControllerRegister()
76 handler.Add("/api/list", &TestController{}, "*:List") 80 handler.Add("/api/list", &TestController{}, "*:List")
77 handler.Add("/person/:last/:first", &TestController{}) 81 handler.Add("/person/:last/:first", &TestController{}, "*:Param")
78 handler.AddAuto(&TestController{}) 82 handler.AddAuto(&TestController{})
79 if handler.UrlFor("TestController.List") != "/api/list" { 83 if handler.UrlFor("TestController.List") != "/api/list" {
80 Info(handler.UrlFor("TestController.List")) 84 Info(handler.UrlFor("TestController.List"))
81 t.Errorf("TestController.List must equal to /api/list") 85 t.Errorf("TestController.List must equal to /api/list")
82 } 86 }
83 if handler.UrlFor("TestController.Get", ":last", "xie", ":first", "asta") != "/person/xie/asta" { 87 if handler.UrlFor("TestController.Param", ":last", "xie", ":first", "asta") != "/person/xie/asta" {
84 t.Errorf("TestController.Get must equal to /person/xie/asta") 88 t.Errorf("TestController.Param must equal to /person/xie/asta, but get " + handler.UrlFor("TestController.Param", ":last", "xie", ":first", "asta"))
85 } 89 }
86 if handler.UrlFor("TestController.Myext") != "/test/myext" { 90 if handler.UrlFor("TestController.Myext") != "/test/myext" {
87 t.Errorf("TestController.Myext must equal to /test/myext") 91 t.Errorf("TestController.Myext must equal to /test/myext")
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!