Skip to content

Commit

Permalink
pprof 移到 apis中
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Sep 4, 2020
1 parent 25f558b commit cd6e6f9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/axiaoxin-com/pink-lady/apis/docs"
"github.com/axiaoxin-com/pink-lady/webserver"
"github.com/gin-contrib/pprof"

// docs is generated by Swag CLI, you have to import it.
_ "github.com/axiaoxin-com/pink-lady/apis/docs"
Expand Down Expand Up @@ -51,6 +52,9 @@ func Register(httpHandler http.Handler) {
// Group x 默认 url 路由
x := app.Group("/x", webserver.GinBasicAuth())
{
if viper.GetBool("server.pprof") {
pprof.RouteRegister(x, "/pprof")
}
// ginSwagger 生成的在线 API 文档路由
x.GET("/apidocs/*any", ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, DisableGinSwaggerEnvkey))
// 默认的 ping 方法,返回 server 相关信息
Expand Down
2 changes: 0 additions & 2 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/axiaoxin-com/goutils v0.0.0-20200903141426-4f3b85da9884 h1:QfXE+0CbZqmsMcfBunvm+KrIuF3v0WuZHGLcfU0gQj0=
github.com/axiaoxin-com/goutils v0.0.0-20200903141426-4f3b85da9884/go.mod h1:qSbS9tJ2k4lVFcawNNdiBjrfIV94qSpCPqzstXMWbXA=
github.com/axiaoxin-com/logging v1.2.3-0.20200904092923-6dd721192906 h1:adyRtC2qUDg1bxGobnC31VgxqMu2XIyYoOUxd9xBZKQ=
github.com/axiaoxin-com/logging v1.2.3-0.20200904092923-6dd721192906/go.mod h1:4nICuwYPRsXnF/kTJ/W3hXNljkCGrQm/VitBW2659RU=
github.com/axiaoxin-com/logging v1.2.3-0.20200904093302-60998122f327 h1:vVXnzXOUWCYhhNHRSjinvPyqdcx0P9n6W+Mdsk75pAI=
github.com/axiaoxin-com/logging v1.2.3-0.20200904093302-60998122f327/go.mod h1:4nICuwYPRsXnF/kTJ/W3hXNljkCGrQm/VitBW2659RU=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
9 changes: 0 additions & 9 deletions src/webserver/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ import (

"github.com/axiaoxin-com/logging"
"github.com/axiaoxin-com/pink-lady/response"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)

var (
// GinPprofURLPath 设置 gin 中的 pprof url 注册路径,可以通过外部修改
GinPprofURLPath = "/x/pprof"
)

// NewGinEngine 根据参数创建 gin 的 router engine
// middlewares 需要使用到的中间件列表,默认不为 engine 添加任何中间件
func NewGinEngine(middlewares ...gin.HandlerFunc) *gin.Engine {
Expand All @@ -36,9 +30,6 @@ func NewGinEngine(middlewares ...gin.HandlerFunc) *gin.Engine {
engine.Use(middleware)
}

if viper.GetBool("server.pprof") {
pprof.Register(engine, GinPprofURLPath)
}
return engine
}

Expand Down

0 comments on commit cd6e6f9

Please sign in to comment.