1 Star 0 Fork 0

曾广宇 / mxx-core-v2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gin_pprof.go 3.14 KB
一键复制 编辑 原始数据 按行查看 历史
曾广宇 提交于 2023-04-13 15:30 . 新增gin pprof支持
package mweb
import (
"gitee.com/dennis-mxx/mxx-core-v2/msystem"
"github.com/gin-gonic/gin"
"net/http/pprof"
)
func InitProf(engine *GinEngine) {
engine.GET("/debug/pprof/", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/heap", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/heap?debug=1", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/mutex", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/block", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/goroutine", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/threadcreate", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/<script>scripty<script>", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Index(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/cmdline", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Cmdline(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/profile", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Profile(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/symbol", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Symbol(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
engine.GET("/debug/pprof/trace", func(context *gin.Context) {
secret := context.Query("secret")
if secret == msystem.Environment.Gin.PprofSecret {
pprof.Trace(context.Writer, context.Request)
} else {
context.AbortWithStatus(503)
}
})
}
1
https://gitee.com/dennis-mxx/mxx-core-v2.git
git@gitee.com:dennis-mxx/mxx-core-v2.git
dennis-mxx
mxx-core-v2
mxx-core-v2
v0.2.6

搜索帮助