14dee37a by astaxie

beego: autorouter params

1 parent 17a9c3c3
...@@ -346,19 +346,23 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) ...@@ -346,19 +346,23 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface)
346 reflectVal := reflect.ValueOf(c) 346 reflectVal := reflect.ValueOf(c)
347 rt := reflectVal.Type() 347 rt := reflectVal.Type()
348 ct := reflect.Indirect(reflectVal).Type() 348 ct := reflect.Indirect(reflectVal).Type()
349 controllerName := strings.ToLower(strings.TrimSuffix(ct.Name(), "Controller")) 349 controllerName := strings.TrimSuffix(ct.Name(), "Controller")
350 for i := 0; i < rt.NumMethod(); i++ { 350 for i := 0; i < rt.NumMethod(); i++ {
351 if !utils.InSlice(rt.Method(i).Name, exceptMethod) { 351 if !utils.InSlice(rt.Method(i).Name, exceptMethod) {
352 route := &controllerInfo{} 352 route := &controllerInfo{}
353 route.routerType = routerTypeBeego 353 route.routerType = routerTypeBeego
354 route.methods = map[string]string{"*": rt.Method(i).Name} 354 route.methods = map[string]string{"*": rt.Method(i).Name}
355 route.controllerType = ct 355 route.controllerType = ct
356 pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") 356 pattern := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name), "*")
357 patternfix := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name)) 357 patternInit := path.Join(prefix, controllerName, rt.Method(i).Name, "*")
358 patternfix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name))
359 patternfixInit := path.Join(prefix, controllerName, rt.Method(i).Name)
358 route.pattern = pattern 360 route.pattern = pattern
359 for _, m := range HTTPMETHOD { 361 for _, m := range HTTPMETHOD {
360 p.addToRouter(m, pattern, route) 362 p.addToRouter(m, pattern, route)
363 p.addToRouter(m, patternInit, route)
361 p.addToRouter(m, patternfix, route) 364 p.addToRouter(m, patternfix, route)
365 p.addToRouter(m, patternfixInit, route)
362 } 366 }
363 } 367 }
364 } 368 }
...@@ -603,7 +607,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -603,7 +607,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
603 607
604 if !findrouter { 608 if !findrouter {
605 if t, ok := p.routers[r.Method]; ok { 609 if t, ok := p.routers[r.Method]; ok {
606 runObject, p := t.Match(strings.ToLower(r.URL.Path)) 610 runObject, p := t.Match(r.URL.Path)
607 if r, ok := runObject.(*controllerInfo); ok { 611 if r, ok := runObject.(*controllerInfo); ok {
608 routerInfo = r 612 routerInfo = r
609 findrouter = true 613 findrouter = true
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!