Skip to content

Commit

Permalink
[feature] pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
runs committed Mar 24, 2023
1 parent b2a6245 commit d404aee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/TheZeroSlave/zapsentry v1.14.0
github.com/getsentry/sentry-go v0.18.0
github.com/gin-contrib/pprof v1.4.0
github.com/gin-contrib/zap v0.1.0
github.com/gin-gonic/gin v1.9.0
github.com/go-playground/validator/v10 v10.11.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0=
github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ=
github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg=
github.com/gin-contrib/pprof v1.4.0/go.mod h1:RrehPJasUVBPK6yTUwOl8/NP6i0vbUgmxtis+Z5KE90=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/zap v0.1.0 h1:RMSFFJo34XZogV62OgOzvrlaMNmXrNxmJ3bFmMwl6Cc=
Expand Down
10 changes: 7 additions & 3 deletions internal/pkg/httpserver/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package httpserver
import (
"context"
"fmt"
"net/http"
"time"

"github.com/gin-contrib/pprof"
ginZap "github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"go.uber.org/fx"
"go.uber.org/zap"
"net/http"
"time"
)

type Server struct {
Expand All @@ -28,6 +28,10 @@ func NewRouter(c *Config, logger *zap.Logger, init InitRouters) *gin.Engine {
// 初始化 gin
r := gin.New()

if c.Mode == "debug" {
pprof.Register(r)
}

// panic之后自动恢复
r.Use(gin.Recovery())
r.Use(ginZap.Ginzap(logger, time.RFC3339, true))
Expand Down

0 comments on commit d404aee

Please sign in to comment.