diff --git a/README.md b/README.md index 4976e76..6676b76 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,34 @@ func main() { } ``` +### custom router group + +```go +package main + +import ( + "net/http" + + "github.com/gin-contrib/pprof" + "github.com/gin-gonic/gin" +) + +func main() { + router := gin.Default() + pprof.Register(router) + adminGroup := r.Group("/admin", func(c *gin.Context) { + if c.Request.Header.Get("Authorization") != "foobar" { + c.AbortWithStatus(http.StatusForbidden) + return + } + c.Next() + }) + pprof.RouteRegister(adminGroup, "pprof") + router.Run(":8080") +} + +``` + ### Use the pprof tool Then use the pprof tool to look at the heap profile: diff --git a/example/custom/server.go b/example/custom/server.go new file mode 100644 index 0000000..2b8b9a7 --- /dev/null +++ b/example/custom/server.go @@ -0,0 +1,22 @@ +package main + +import ( + "net/http" + + "github.com/gin-contrib/pprof" + "github.com/gin-gonic/gin" +) + +func main() { + router := gin.Default() + pprof.Register(router) + adminGroup := r.Group("/admin", func(c *gin.Context) { + if c.Request.Header.Get("Authorization") != "foobar" { + c.AbortWithStatus(http.StatusForbidden) + return + } + c.Next() + }) + pprof.RouteRegister(adminGroup, "pprof") + router.Run(":8080") +} diff --git a/example/server.go b/example/default/server.go similarity index 100% rename from example/server.go rename to example/default/server.go