From c366c346443ca38e6c0444dc7adb14569be044a4 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Tue, 28 Apr 2020 05:42:23 +0300 Subject: [PATCH] add human-friendly middleware names on route debugging (see HISTORY.md#Next) Former-commit-id: f7291c4a077c4d1573344c93ba8a153fede18795 --- _examples/orm/gorm/main.go | 2 +- _examples/websocket/socketio/main.go | 2 +- core/router/handler.go | 4 ++-- core/router/route.go | 1 + iris.go | 31 ++++++++++++++++------------ middleware/basicauth/basicauth.go | 4 ++++ middleware/hcaptcha/hcaptcha.go | 4 ++++ middleware/pprof/pprof.go | 4 ++++ middleware/recaptcha/recaptcha.go | 4 ++++ middleware/recover/recover.go | 4 ++++ 10 files changed, 43 insertions(+), 17 deletions(-) diff --git a/_examples/orm/gorm/main.go b/_examples/orm/gorm/main.go index 534e56db..d0906109 100644 --- a/_examples/orm/gorm/main.go +++ b/_examples/orm/gorm/main.go @@ -165,7 +165,7 @@ func main() { "data": user.Serializer(), }) }) - + app.Listen(":8080") } diff --git a/_examples/websocket/socketio/main.go b/_examples/websocket/socketio/main.go index c4e0250d..49078307 100644 --- a/_examples/websocket/socketio/main.go +++ b/_examples/websocket/socketio/main.go @@ -47,7 +47,7 @@ func main() { app.HandleMany("GET POST", "/socket.io/{any:path}", iris.FromStd(server)) app.HandleDir("/", "./asset") - + app.Listen(":8000", iris.WithoutPathCorrection) } diff --git a/core/router/handler.go b/core/router/handler.go index d04a7961..0fb0f57e 100644 --- a/core/router/handler.go +++ b/core/router/handler.go @@ -132,7 +132,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error { for _, r := range registeredRoutes { if h.config != nil && h.config.GetForceLowercaseRouting() { - // only in that state, keep everyting else as end-developer registered. + // only in that state, keep everything else as end-developer registered. r.Path = strings.ToLower(r.Path) } @@ -162,7 +162,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error { tr = tr[0 : len(tr)-1] } - golog.Debugf("API: [%d] %s", len(registeredRoutes), tr) + golog.Debugf("API: %d registered %s", len(registeredRoutes), tr) // group routes by method and print them without the [DBUG] and time info, // the route logs are colorful. diff --git a/core/router/route.go b/core/router/route.go index 5b814ebb..5ad77d75 100644 --- a/core/router/route.go +++ b/core/router/route.go @@ -343,6 +343,7 @@ func (r *Route) ResolvePath(args ...string) string { var ignoreHandlersTraces = [...]string{ "iris/macro/handler.MakeHandler", + "iris/hero.makeHandler.func2", "iris/core/router.(*APIBuilder).Favicon", "iris/core/router.StripPrefix", } diff --git a/iris.go b/iris.go index ece3f40a..8243b303 100644 --- a/iris.go +++ b/iris.go @@ -768,6 +768,24 @@ func (app *Application) Build() error { app.Router.WrapRouter(app.I18n.Wrapper()) } + if n := app.view.Len(); n > 0 { + tr := "engines" + if n == 1 { + tr = tr[0 : len(tr)-1] + } + + app.logger.Debugf("Application: %d registered view %s", n, tr) + // view engine + // here is where we declare the closed-relative framework functions. + // Each engine has their defaults, i.e yield,render,render_r,partial, params... + rv := router.NewRoutePathReverser(app.APIBuilder) + app.view.AddFunc("urlpath", rv.Path) + // app.view.AddFunc("url", rv.URL) + if err := app.view.Load(); err != nil { + rp.Group("View Builder").Err(err) + } + } + if !app.Router.Downgraded() { // router if err := app.tryInjectLiveReload(); err != nil { @@ -790,19 +808,6 @@ func (app *Application) Build() error { // re-build of the router from outside can be done with // app.RefreshRouter() } - - if app.view.Len() > 0 { - app.logger.Debugf("Application: %d registered view engine(s)", app.view.Len()) - // view engine - // here is where we declare the closed-relative framework functions. - // Each engine has their defaults, i.e yield,render,render_r,partial, params... - rv := router.NewRoutePathReverser(app.APIBuilder) - app.view.AddFunc("urlpath", rv.Path) - // app.view.AddFunc("url", rv.URL) - if err := app.view.Load(); err != nil { - rp.Group("View Builder").Err(err) - } - } } return errgroup.Check(rp) diff --git a/middleware/basicauth/basicauth.go b/middleware/basicauth/basicauth.go index e3938f6d..1851139a 100644 --- a/middleware/basicauth/basicauth.go +++ b/middleware/basicauth/basicauth.go @@ -12,6 +12,10 @@ import ( "github.com/kataras/iris/v12/context" ) +func init() { + context.SetHandlerName("iris/middleware/basicauth.*", "Basic Authentication") +} + type ( encodedUser struct { HeaderValue string diff --git a/middleware/hcaptcha/hcaptcha.go b/middleware/hcaptcha/hcaptcha.go index fc7ecc3f..7b385e4f 100644 --- a/middleware/hcaptcha/hcaptcha.go +++ b/middleware/hcaptcha/hcaptcha.go @@ -10,6 +10,10 @@ import ( "github.com/kataras/iris/v12/context" ) +func init() { + context.SetHandlerName("iris/middleware/hcaptcha.*", "hCaptcha") +} + var ( // ResponseContextKey is the default request's context key that response of a hcaptcha request is kept. ResponseContextKey string = "iris.hcaptcha" diff --git a/middleware/pprof/pprof.go b/middleware/pprof/pprof.go index 82810a98..f1e1309c 100644 --- a/middleware/pprof/pprof.go +++ b/middleware/pprof/pprof.go @@ -11,6 +11,10 @@ import ( "github.com/kataras/iris/v12/core/handlerconv" ) +func init() { + context.SetHandlerName("iris/middleware/pprof.*", "Profiling") +} + // New returns a new pprof (profile, cmdline, symbol, goroutine, heap, threadcreate, debug/block) Middleware. // Note: Route MUST have the last named parameter wildcard named '{action:path}' func New() context.Handler { diff --git a/middleware/recaptcha/recaptcha.go b/middleware/recaptcha/recaptcha.go index cd54a66b..c6cf9501 100644 --- a/middleware/recaptcha/recaptcha.go +++ b/middleware/recaptcha/recaptcha.go @@ -11,6 +11,10 @@ import ( "github.com/kataras/iris/v12/core/netutil" ) +func init() { + context.SetHandlerName("iris/middleware/recaptcha.*", "reCAPTCHA") +} + const ( // responseFormValue = "g-recaptcha-response" apiURL = "https://www.google.com/recaptcha/api/siteverify" diff --git a/middleware/recover/recover.go b/middleware/recover/recover.go index 21fabb77..809fd8cf 100644 --- a/middleware/recover/recover.go +++ b/middleware/recover/recover.go @@ -9,6 +9,10 @@ import ( "github.com/kataras/iris/v12/context" ) +func init() { + context.SetHandlerName("iris/middleware/recover.*", "Panic Recover") +} + func getRequestLogs(ctx context.Context) string { var status, ip, method, path string status = strconv.Itoa(ctx.GetStatusCode())