diff --git a/adaptors/gorillamux/gorillamux.go b/adaptors/gorillamux/gorillamux.go index 97124fd6..74f915ba 100644 --- a/adaptors/gorillamux/gorillamux.go +++ b/adaptors/gorillamux/gorillamux.go @@ -190,7 +190,7 @@ func registerRoute(route iris.RouteInfo, gorillaRouter *mux.Router, context iris subdomain := route.Subdomain() if subdomain != "" { - if subdomain == "*." { + if subdomain == iris.DynamicSubdomainIndicator { // it's an iris wildcard subdomain // so register it as wildcard on gorilla mux too subdomain = "{subdomain}." diff --git a/middleware/pprof/_example/main.go b/middleware/pprof/_example/main.go new file mode 100644 index 00000000..cc12a099 --- /dev/null +++ b/middleware/pprof/_example/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "gopkg.in/kataras/iris.v6" + "gopkg.in/kataras/iris.v6/adaptors/httprouter" + "gopkg.in/kataras/iris.v6/middleware/pprof" +) + +func main() { + app := iris.New() + app.Adapt(iris.DevLogger()) + app.Adapt(httprouter.New()) + + app.Get("/", func(ctx *iris.Context) { + ctx.HTML(iris.StatusOK, "

Please click here") + }) + + app.Get("/debug/pprof/*action", pprof.New()) + // ___________ + // Note: + // if you prefer gorillamux adaptor, then + // the wildcard for gorilla mux (as you already know) is '{action:.*}' instead of '*action'. + app.Listen(":8080") +} diff --git a/middleware/pprof/pprof.go b/middleware/pprof/pprof.go new file mode 100644 index 00000000..600b75fb --- /dev/null +++ b/middleware/pprof/pprof.go @@ -0,0 +1,59 @@ +// Package pprof usage: app.Get(iris.RouteWildcardPath("/debug/pprof", "action"), pprof.New()) +// for specific router adaptors follow these optional route syntax: +// 'adaptors/httprouter': +// +// app := iris.New() +// app.Adapt(httprouter.New()) +// app.Get("/debug/pprof/*action", pprof.New()) +// +// 'adaptors/gorillamux': +// +// app := iris.New() +// app.Adapt(gorillamux.New()) +// app.Get("/debug/pprof/{action:.*}", pprof.New()) +package pprof + +import ( + "net/http/pprof" + "strings" + + "gopkg.in/kataras/iris.v6" +) + +// 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' +func New() iris.HandlerFunc { + indexHandler := iris.ToHandler(pprof.Index) + cmdlineHandler := iris.ToHandler(pprof.Cmdline) + profileHandler := iris.ToHandler(pprof.Profile) + symbolHandler := iris.ToHandler(pprof.Symbol) + goroutineHandler := iris.ToHandler(pprof.Handler("goroutine")) + heapHandler := iris.ToHandler(pprof.Handler("heap")) + threadcreateHandler := iris.ToHandler(pprof.Handler("threadcreate")) + debugBlockHandler := iris.ToHandler(pprof.Handler("block")) + + return iris.HandlerFunc(func(ctx *iris.Context) { + ctx.SetContentType("text/html; charset=" + ctx.Framework().Config.Charset) + + action := ctx.Param("action") + if len(action) > 1 { + if strings.Contains(action, "cmdline") { + cmdlineHandler.Serve((ctx)) + } else if strings.Contains(action, "profile") { + profileHandler.Serve(ctx) + } else if strings.Contains(action, "symbol") { + symbolHandler.Serve(ctx) + } else if strings.Contains(action, "goroutine") { + goroutineHandler.Serve(ctx) + } else if strings.Contains(action, "heap") { + heapHandler.Serve(ctx) + } else if strings.Contains(action, "threadcreate") { + threadcreateHandler.Serve(ctx) + } else if strings.Contains(action, "debug/block") { + debugBlockHandler.Serve(ctx) + } + } else { + indexHandler.Serve(ctx) + } + }) +}