...

Source file src/github.com/gin-contrib/pprof/pprof.go

Documentation: github.com/gin-contrib/pprof

     1  package pprof
     2  
     3  import (
     4  	"net/http/pprof"
     5  
     6  	"github.com/gin-gonic/gin"
     7  )
     8  
     9  const (
    10  	// DefaultPrefix url prefix of pprof
    11  	DefaultPrefix = "/debug/pprof"
    12  )
    13  
    14  func getPrefix(prefixOptions ...string) string {
    15  	prefix := DefaultPrefix
    16  	if len(prefixOptions) > 0 {
    17  		prefix = prefixOptions[0]
    18  	}
    19  	return prefix
    20  }
    21  
    22  // Register the standard HandlerFuncs from the net/http/pprof package with
    23  // the provided gin.Engine. prefixOptions is a optional. If not prefixOptions,
    24  // the default path prefix is used, otherwise first prefixOptions will be path prefix.
    25  func Register(r *gin.Engine, prefixOptions ...string) {
    26  	RouteRegister(&(r.RouterGroup), prefixOptions...)
    27  }
    28  
    29  // RouteRegister the standard HandlerFuncs from the net/http/pprof package with
    30  // the provided gin.GrouterGroup. prefixOptions is a optional. If not prefixOptions,
    31  // the default path prefix is used, otherwise first prefixOptions will be path prefix.
    32  func RouteRegister(rg *gin.RouterGroup, prefixOptions ...string) {
    33  	prefix := getPrefix(prefixOptions...)
    34  
    35  	prefixRouter := rg.Group(prefix)
    36  	{
    37  		prefixRouter.GET("/", gin.WrapF(pprof.Index))
    38  		prefixRouter.GET("/cmdline", gin.WrapF(pprof.Cmdline))
    39  		prefixRouter.GET("/profile", gin.WrapF(pprof.Profile))
    40  		prefixRouter.POST("/symbol", gin.WrapF(pprof.Symbol))
    41  		prefixRouter.GET("/symbol", gin.WrapF(pprof.Symbol))
    42  		prefixRouter.GET("/trace", gin.WrapF(pprof.Trace))
    43  		prefixRouter.GET("/allocs", gin.WrapH(pprof.Handler("allocs")))
    44  		prefixRouter.GET("/block", gin.WrapH(pprof.Handler("block")))
    45  		prefixRouter.GET("/goroutine", gin.WrapH(pprof.Handler("goroutine")))
    46  		prefixRouter.GET("/heap", gin.WrapH(pprof.Handler("heap")))
    47  		prefixRouter.GET("/mutex", gin.WrapH(pprof.Handler("mutex")))
    48  		prefixRouter.GET("/threadcreate", gin.WrapH(pprof.Handler("threadcreate")))
    49  	}
    50  }
    51  

View as plain text