mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:21:02 +00:00
beego: dev mode print request router & pattern
This commit is contained in:
parent
dbebf8df4b
commit
107a7a21c0
@ -165,7 +165,7 @@ func compareFile(pkgRealpath string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if v, ok := pkgLastupdate[pkgRealpath]; ok {
|
if v, ok := pkgLastupdate[pkgRealpath]; ok {
|
||||||
if ft.ModTime().UnixNano() > v {
|
if ft.ModTime().UnixNano() >= v {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
router.go
16
router.go
@ -60,6 +60,7 @@ func ExceptMethodAppend(action string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type controllerInfo struct {
|
type controllerInfo struct {
|
||||||
|
pattern string
|
||||||
controllerType reflect.Type
|
controllerType reflect.Type
|
||||||
methods map[string]string
|
methods map[string]string
|
||||||
handler http.Handler
|
handler http.Handler
|
||||||
@ -119,6 +120,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
|
|||||||
}
|
}
|
||||||
|
|
||||||
route := &controllerInfo{}
|
route := &controllerInfo{}
|
||||||
|
route.pattern = pattern
|
||||||
route.methods = methods
|
route.methods = methods
|
||||||
route.routerType = routerTypeBeego
|
route.routerType = routerTypeBeego
|
||||||
route.controllerType = t
|
route.controllerType = t
|
||||||
@ -273,6 +275,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) {
|
|||||||
panic("not support http method: " + method)
|
panic("not support http method: " + method)
|
||||||
}
|
}
|
||||||
route := &controllerInfo{}
|
route := &controllerInfo{}
|
||||||
|
route.pattern = pattern
|
||||||
route.routerType = routerTypeRESTFul
|
route.routerType = routerTypeRESTFul
|
||||||
route.runfunction = f
|
route.runfunction = f
|
||||||
methods := make(map[string]string)
|
methods := make(map[string]string)
|
||||||
@ -298,6 +301,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) {
|
|||||||
// add user defined Handler
|
// add user defined Handler
|
||||||
func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{}) {
|
func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{}) {
|
||||||
route := &controllerInfo{}
|
route := &controllerInfo{}
|
||||||
|
route.pattern = pattern
|
||||||
route.routerType = routerTypeHandler
|
route.routerType = routerTypeHandler
|
||||||
route.handler = h
|
route.handler = h
|
||||||
if len(options) > 0 {
|
if len(options) > 0 {
|
||||||
@ -336,6 +340,7 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface)
|
|||||||
route.methods = map[string]string{"*": rt.Method(i).Name}
|
route.methods = map[string]string{"*": rt.Method(i).Name}
|
||||||
route.controllerType = ct
|
route.controllerType = ct
|
||||||
pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*")
|
pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*")
|
||||||
|
route.pattern = pattern
|
||||||
for _, m := range HTTPMETHOD {
|
for _, m := range HTTPMETHOD {
|
||||||
p.addToRouter(m, pattern, route)
|
p.addToRouter(m, pattern, route)
|
||||||
}
|
}
|
||||||
@ -502,7 +507,6 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
// Implement http.Handler interface.
|
// Implement http.Handler interface.
|
||||||
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||||
defer p.recoverPanic(rw, r)
|
defer p.recoverPanic(rw, r)
|
||||||
|
|
||||||
starttime := time.Now()
|
starttime := time.Now()
|
||||||
requestPath := r.URL.Path
|
requestPath := r.URL.Path
|
||||||
method := strings.ToLower(r.Method)
|
method := strings.ToLower(r.Method)
|
||||||
@ -718,9 +722,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
do_filter(FinishRouter)
|
do_filter(FinishRouter)
|
||||||
|
|
||||||
Admin:
|
Admin:
|
||||||
|
timeend := time.Since(starttime)
|
||||||
//admin module record QPS
|
//admin module record QPS
|
||||||
if EnableAdmin {
|
if EnableAdmin {
|
||||||
timeend := time.Since(starttime)
|
|
||||||
if FilterMonitorFunc(r.Method, requestPath, timeend) {
|
if FilterMonitorFunc(r.Method, requestPath, timeend) {
|
||||||
if runrouter != nil {
|
if runrouter != nil {
|
||||||
go toolbox.StatisticsMap.AddStatistics(r.Method, requestPath, runrouter.Name(), timeend)
|
go toolbox.StatisticsMap.AddStatistics(r.Method, requestPath, runrouter.Name(), timeend)
|
||||||
@ -729,6 +733,14 @@ Admin:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if RunMode == "dev" {
|
||||||
|
if findrouter {
|
||||||
|
Info("beego: router defined " + routerInfo.pattern + " " + requestPath + " +" + timeend.String())
|
||||||
|
} else {
|
||||||
|
Info("beego:" + requestPath + " 404" + " +" + timeend.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) {
|
func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user