Skip to content

Commit

Permalink
docs: add custom router group
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Apr 23, 2020
1 parent 4b18fd3 commit 7fd5039
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions example/custom/server.go
Original file line number Diff line number Diff line change
@@ -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")
}
File renamed without changes.

0 comments on commit 7fd5039

Please sign in to comment.