beego: dev mode print request router & pattern
Showing
2 changed files
with
15 additions
and
3 deletions
| ... | @@ -165,7 +165,7 @@ func compareFile(pkgRealpath string) bool { | ... | @@ -165,7 +165,7 @@ func compareFile(pkgRealpath string) bool { |
| 165 | return true | 165 | return true |
| 166 | } | 166 | } |
| 167 | if v, ok := pkgLastupdate[pkgRealpath]; ok { | 167 | if v, ok := pkgLastupdate[pkgRealpath]; ok { |
| 168 | if ft.ModTime().UnixNano() > v { | 168 | if ft.ModTime().UnixNano() >= v { |
| 169 | return false | 169 | return false |
| 170 | } | 170 | } |
| 171 | } | 171 | } | ... | ... |
| ... | @@ -60,6 +60,7 @@ func ExceptMethodAppend(action string) { | ... | @@ -60,6 +60,7 @@ func ExceptMethodAppend(action string) { |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | type controllerInfo struct { | 62 | type controllerInfo struct { |
| 63 | pattern string | ||
| 63 | controllerType reflect.Type | 64 | controllerType reflect.Type |
| 64 | methods map[string]string | 65 | methods map[string]string |
| 65 | handler http.Handler | 66 | handler http.Handler |
| ... | @@ -119,6 +120,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM | ... | @@ -119,6 +120,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | route := &controllerInfo{} | 122 | route := &controllerInfo{} |
| 123 | route.pattern = pattern | ||
| 122 | route.methods = methods | 124 | route.methods = methods |
| 123 | route.routerType = routerTypeBeego | 125 | route.routerType = routerTypeBeego |
| 124 | route.controllerType = t | 126 | route.controllerType = t |
| ... | @@ -273,6 +275,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) { | ... | @@ -273,6 +275,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) { |
| 273 | panic("not support http method: " + method) | 275 | panic("not support http method: " + method) |
| 274 | } | 276 | } |
| 275 | route := &controllerInfo{} | 277 | route := &controllerInfo{} |
| 278 | route.pattern = pattern | ||
| 276 | route.routerType = routerTypeRESTFul | 279 | route.routerType = routerTypeRESTFul |
| 277 | route.runfunction = f | 280 | route.runfunction = f |
| 278 | methods := make(map[string]string) | 281 | methods := make(map[string]string) |
| ... | @@ -298,6 +301,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) { | ... | @@ -298,6 +301,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) { |
| 298 | // add user defined Handler | 301 | // add user defined Handler |
| 299 | func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{}) { | 302 | func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{}) { |
| 300 | route := &controllerInfo{} | 303 | route := &controllerInfo{} |
| 304 | route.pattern = pattern | ||
| 301 | route.routerType = routerTypeHandler | 305 | route.routerType = routerTypeHandler |
| 302 | route.handler = h | 306 | route.handler = h |
| 303 | if len(options) > 0 { | 307 | if len(options) > 0 { |
| ... | @@ -336,6 +340,7 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) | ... | @@ -336,6 +340,7 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) |
| 336 | route.methods = map[string]string{"*": rt.Method(i).Name} | 340 | route.methods = map[string]string{"*": rt.Method(i).Name} |
| 337 | route.controllerType = ct | 341 | route.controllerType = ct |
| 338 | pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") | 342 | pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") |
| 343 | route.pattern = pattern | ||
| 339 | for _, m := range HTTPMETHOD { | 344 | for _, m := range HTTPMETHOD { |
| 340 | p.addToRouter(m, pattern, route) | 345 | p.addToRouter(m, pattern, route) |
| 341 | } | 346 | } |
| ... | @@ -502,7 +507,6 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin | ... | @@ -502,7 +507,6 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin |
| 502 | // Implement http.Handler interface. | 507 | // Implement http.Handler interface. |
| 503 | func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) { | 508 | func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) { |
| 504 | defer p.recoverPanic(rw, r) | 509 | defer p.recoverPanic(rw, r) |
| 505 | |||
| 506 | starttime := time.Now() | 510 | starttime := time.Now() |
| 507 | requestPath := r.URL.Path | 511 | requestPath := r.URL.Path |
| 508 | method := strings.ToLower(r.Method) | 512 | method := strings.ToLower(r.Method) |
| ... | @@ -718,9 +722,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -718,9 +722,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 718 | do_filter(FinishRouter) | 722 | do_filter(FinishRouter) |
| 719 | 723 | ||
| 720 | Admin: | 724 | Admin: |
| 725 | timeend := time.Since(starttime) | ||
| 721 | //admin module record QPS | 726 | //admin module record QPS |
| 722 | if EnableAdmin { | 727 | if EnableAdmin { |
| 723 | timeend := time.Since(starttime) | ||
| 724 | if FilterMonitorFunc(r.Method, requestPath, timeend) { | 728 | if FilterMonitorFunc(r.Method, requestPath, timeend) { |
| 725 | if runrouter != nil { | 729 | if runrouter != nil { |
| 726 | go toolbox.StatisticsMap.AddStatistics(r.Method, requestPath, runrouter.Name(), timeend) | 730 | go toolbox.StatisticsMap.AddStatistics(r.Method, requestPath, runrouter.Name(), timeend) |
| ... | @@ -729,6 +733,14 @@ Admin: | ... | @@ -729,6 +733,14 @@ Admin: |
| 729 | } | 733 | } |
| 730 | } | 734 | } |
| 731 | } | 735 | } |
| 736 | |||
| 737 | if RunMode == "dev" { | ||
| 738 | if findrouter { | ||
| 739 | Info("beego: router defined " + routerInfo.pattern + " " + requestPath + " +" + timeend.String()) | ||
| 740 | } else { | ||
| 741 | Info("beego:" + requestPath + " 404" + " +" + timeend.String()) | ||
| 742 | } | ||
| 743 | } | ||
| 732 | } | 744 | } |
| 733 | 745 | ||
| 734 | func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) { | 746 | func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) { | ... | ... |
-
Please register or sign in to post a comment