From cd6e6f9b28acd7fc59ef9fbbff123e8f0d7255da Mon Sep 17 00:00:00 2001 From: axiaoxin <254606826@qq.com> Date: Fri, 4 Sep 2020 19:57:32 +0800 Subject: [PATCH] =?UTF-8?q?pprof=20=E7=A7=BB=E5=88=B0=20apis=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/apis.go | 4 ++++ src/go.sum | 2 -- src/webserver/gin.go | 9 --------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/apis/apis.go b/src/apis/apis.go index 4324069..173ff7f 100644 --- a/src/apis/apis.go +++ b/src/apis/apis.go @@ -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" @@ -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 相关信息 diff --git a/src/go.sum b/src/go.sum index 3ef40f3..3c2d467 100644 --- a/src/go.sum +++ b/src/go.sum @@ -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= diff --git a/src/webserver/gin.go b/src/webserver/gin.go index 44bd35a..2897642 100644 --- a/src/webserver/gin.go +++ b/src/webserver/gin.go @@ -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 { @@ -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 }