Repository: DeanThompson/ginpprof
Branch: master
Commit: 007b1e56b2e1
Files: 7
Total size: 9.4 KB
Directory structure:
gitextract_z_jy1e1m/
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── example/
│ └── example.go
├── pprof.go
└── pprof_test.go
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
================================================
FILE: .travis.yml
================================================
language: go
arch:
- AMD64
- ppc64le
go:
- 1.12
- 1.13
- 1.14
- 1.15
script:
- go test
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2015 Yangliang Li
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
ginpprof
========
[](https://godoc.org/github.com/DeanThompson/ginpprof)
[](https://travis-ci.org/DeanThompson/ginpprof)
A wrapper for [golang web framework gin](https://github.com/gin-gonic/gin) to use `net/http/pprof` easily.
## Install
First install ginpprof to your GOPATH using `go get`:
```sh
go get github.com/DeanThompson/ginpprof
```
## Usage
```go
package main
import (
"github.com/gin-gonic/gin"
"github.com/DeanThompson/ginpprof"
)
func main() {
router := gin.Default()
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
// automatically add routers for net/http/pprof
// e.g. /debug/pprof, /debug/pprof/heap, etc.
ginpprof.Wrap(router)
// ginpprof also plays well with *gin.RouterGroup
// group := router.Group("/debug/pprof")
// ginpprof.WrapGroup(group)
router.Run(":8080")
}
```
Start this server, and you will see such outputs:
```text
[GIN-debug] GET /ping --> main.main.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/ --> github.com/DeanThompson/ginpprof.IndexHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/heap --> github.com/DeanThompson/ginpprof.HeapHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/goroutine --> github.com/DeanThompson/ginpprof.GoroutineHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/block --> github.com/DeanThompson/ginpprof.BlockHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/threadcreate --> github.com/DeanThompson/ginpprof.ThreadCreateHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/cmdline --> github.com/DeanThompson/ginpprof.CmdlineHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/profile --> github.com/DeanThompson/ginpprof.ProfileHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/symbol --> github.com/DeanThompson/ginpprof.SymbolHandler.func1 (3 handlers)
[GIN-debug] POST /debug/pprof/symbol --> github.com/DeanThompson/ginpprof.SymbolHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/trace --> github.com/DeanThompson/ginpprof.TraceHandler.func1 (3 handlers)
[GIN-debug] GET /debug/pprof/mutex --> github.com/DeanThompson/ginpprof.MutexHandler.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080
```
Now visit [http://127.0.0.1:8080/debug/pprof/](http://127.0.0.1:8080/debug/pprof/) and you'll see what you want.
Have Fun.
================================================
FILE: example/example.go
================================================
package main
import (
"github.com/gin-gonic/gin"
"github.com/DeanThompson/ginpprof"
)
func main() {
router := gin.Default()
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
// automatically add routers for net/http/pprof
// e.g. /debug/pprof, /debug/pprof/heap, etc.
ginpprof.Wrap(router)
// ginpprof also plays well with *gin.RouterGroup
// group := router.Group("/debug/pprof")
// ginpprof.WrapGroup(group)
router.Run(":8080")
}
================================================
FILE: pprof.go
================================================
package ginpprof
import (
"net/http/pprof"
"strings"
"github.com/gin-gonic/gin"
)
// Wrap adds several routes from package `net/http/pprof` to *gin.Engine object
func Wrap(router *gin.Engine) {
WrapGroup(&router.RouterGroup)
}
// Wrapper make sure we are backward compatible
var Wrapper = Wrap
// WrapGroup adds several routes from package `net/http/pprof` to *gin.RouterGroup object
func WrapGroup(router *gin.RouterGroup) {
routers := []struct {
Method string
Path string
Handler gin.HandlerFunc
}{
{"GET", "/debug/pprof/", IndexHandler()},
{"GET", "/debug/pprof/heap", HeapHandler()},
{"GET", "/debug/pprof/goroutine", GoroutineHandler()},
{"GET", "/debug/pprof/allocs", AllocsHandler()},
{"GET", "/debug/pprof/block", BlockHandler()},
{"GET", "/debug/pprof/threadcreate", ThreadCreateHandler()},
{"GET", "/debug/pprof/cmdline", CmdlineHandler()},
{"GET", "/debug/pprof/profile", ProfileHandler()},
{"GET", "/debug/pprof/symbol", SymbolHandler()},
{"POST", "/debug/pprof/symbol", SymbolHandler()},
{"GET", "/debug/pprof/trace", TraceHandler()},
{"GET", "/debug/pprof/mutex", MutexHandler()},
}
basePath := strings.TrimSuffix(router.BasePath(), "/")
var prefix string
switch {
case basePath == "":
prefix = ""
case strings.HasSuffix(basePath, "/debug"):
prefix = "/debug"
case strings.HasSuffix(basePath, "/debug/pprof"):
prefix = "/debug/pprof"
}
for _, r := range routers {
router.Handle(r.Method, strings.TrimPrefix(r.Path, prefix), r.Handler)
}
}
// IndexHandler will pass the call from /debug/pprof to pprof
func IndexHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Index(ctx.Writer, ctx.Request)
}
}
// HeapHandler will pass the call from /debug/pprof/heap to pprof
func HeapHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Handler("heap").ServeHTTP(ctx.Writer, ctx.Request)
}
}
// GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof
func GoroutineHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Handler("goroutine").ServeHTTP(ctx.Writer, ctx.Request)
}
}
// AllocsHandler will pass the call from /debug/pprof/allocs to pprof
func AllocsHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Handler("allocs").ServeHTTP(ctx.Writer, ctx.Request)
}
}
// BlockHandler will pass the call from /debug/pprof/block to pprof
func BlockHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Handler("block").ServeHTTP(ctx.Writer, ctx.Request)
}
}
// ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof
func ThreadCreateHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Handler("threadcreate").ServeHTTP(ctx.Writer, ctx.Request)
}
}
// CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof
func CmdlineHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Cmdline(ctx.Writer, ctx.Request)
}
}
// ProfileHandler will pass the call from /debug/pprof/profile to pprof
func ProfileHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Profile(ctx.Writer, ctx.Request)
}
}
// SymbolHandler will pass the call from /debug/pprof/symbol to pprof
func SymbolHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Symbol(ctx.Writer, ctx.Request)
}
}
// TraceHandler will pass the call from /debug/pprof/trace to pprof
func TraceHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Trace(ctx.Writer, ctx.Request)
}
}
// MutexHandler will pass the call from /debug/pprof/mutex to pprof
func MutexHandler() gin.HandlerFunc {
return func(ctx *gin.Context) {
pprof.Handler("mutex").ServeHTTP(ctx.Writer, ctx.Request)
}
}
================================================
FILE: pprof_test.go
================================================
package ginpprof
import (
"strings"
"testing"
"github.com/gin-gonic/gin"
)
func newServer() *gin.Engine {
r := gin.Default()
return r
}
func checkRouters(routers gin.RoutesInfo, t *testing.T) {
expectedRouters := map[string]string{
"/debug/pprof/": "IndexHandler",
"/debug/pprof/heap": "HeapHandler",
"/debug/pprof/goroutine": "GoroutineHandler",
"/debug/pprof/allocs": "AllocsHandler",
"/debug/pprof/block": "BlockHandler",
"/debug/pprof/threadcreate": "ThreadCreateHandler",
"/debug/pprof/cmdline": "CmdlineHandler",
"/debug/pprof/profile": "ProfileHandler",
"/debug/pprof/symbol": "SymbolHandler",
"/debug/pprof/trace": "TraceHandler",
"/debug/pprof/mutex": "MutexHandler",
}
for _, router := range routers {
//fmt.Println(router.Path, router.Method, router.Handler)
name, ok := expectedRouters[router.Path]
if !ok {
t.Errorf("missing router %s", router.Path)
}
if !strings.Contains(router.Handler, name) {
t.Errorf("handler for %s should contain %s, got %s", router.Path, name, router.Handler)
}
}
}
func TestWrap(t *testing.T) {
r := newServer()
Wrap(r)
checkRouters(r.Routes(), t)
}
func TestWrapGroup(t *testing.T) {
for _, prefix := range []string{"/debug", "/debug/", "/debug/pprof", "/debug/pprof/"} {
r := newServer()
g := r.Group(prefix)
WrapGroup(g)
checkRouters(r.Routes(), t)
}
}
gitextract_z_jy1e1m/ ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── example/ │ └── example.go ├── pprof.go └── pprof_test.go
SYMBOL INDEX (18 symbols across 3 files)
FILE: example/example.go
function main (line 9) | func main() {
FILE: pprof.go
function Wrap (line 11) | func Wrap(router *gin.Engine) {
function WrapGroup (line 19) | func WrapGroup(router *gin.RouterGroup) {
function IndexHandler (line 57) | func IndexHandler() gin.HandlerFunc {
function HeapHandler (line 64) | func HeapHandler() gin.HandlerFunc {
function GoroutineHandler (line 71) | func GoroutineHandler() gin.HandlerFunc {
function AllocsHandler (line 78) | func AllocsHandler() gin.HandlerFunc {
function BlockHandler (line 85) | func BlockHandler() gin.HandlerFunc {
function ThreadCreateHandler (line 92) | func ThreadCreateHandler() gin.HandlerFunc {
function CmdlineHandler (line 99) | func CmdlineHandler() gin.HandlerFunc {
function ProfileHandler (line 106) | func ProfileHandler() gin.HandlerFunc {
function SymbolHandler (line 113) | func SymbolHandler() gin.HandlerFunc {
function TraceHandler (line 120) | func TraceHandler() gin.HandlerFunc {
function MutexHandler (line 127) | func MutexHandler() gin.HandlerFunc {
FILE: pprof_test.go
function newServer (line 10) | func newServer() *gin.Engine {
function checkRouters (line 15) | func checkRouters(routers gin.RoutesInfo, t *testing.T) {
function TestWrap (line 42) | func TestWrap(t *testing.T) {
function TestWrapGroup (line 48) | func TestWrapGroup(t *testing.T) {
Condensed preview — 7 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (11K chars).
[
{
"path": ".gitignore",
"chars": 266,
"preview": "# Compiled Object files, Static and Dynamic libs (Shared Objects)\n*.o\n*.a\n*.so\n\n# Folders\n_obj\n_test\n\n# Architecture spe"
},
{
"path": ".travis.yml",
"chars": 102,
"preview": "language: go\narch:\n - AMD64\n - ppc64le\ngo:\n - 1.12\n - 1.13\n - 1.14\n - 1.15\n\nscript:\n - go test\n"
},
{
"path": "LICENSE",
"chars": 1080,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Yangliang Li\n\nPermission is hereby granted, free of charge, to any person obta"
},
{
"path": "README.md",
"chars": 2574,
"preview": "ginpprof\n========\n\n[](https://godoc.org/github.co"
},
{
"path": "example/example.go",
"chars": 471,
"preview": "package main\n\nimport (\n\t\"github.com/gin-gonic/gin\"\n\n\t\"github.com/DeanThompson/ginpprof\"\n)\n\nfunc main() {\n\trouter := gin."
},
{
"path": "pprof.go",
"chars": 3727,
"preview": "package ginpprof\n\nimport (\n\t\"net/http/pprof\"\n\t\"strings\"\n\n\t\"github.com/gin-gonic/gin\"\n)\n\n// Wrap adds several routes from"
},
{
"path": "pprof_test.go",
"chars": 1430,
"preview": "package ginpprof\n\nimport (\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc newServer() *gin.Engine {\n\tr := gi"
}
]
About this extraction
This page contains the full source code of the DeanThompson/ginpprof GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 7 files (9.4 KB), approximately 2.9k tokens, and a symbol index with 18 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.