-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.go
42 lines (33 loc) · 858 Bytes
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package debug
import (
"net/http/pprof"
"github.com/alexfalkowski/go-service/env"
"github.com/arl/statsviz"
"go.uber.org/fx"
"go.uber.org/zap"
)
// RegisterParams for debug.
type RegisterParams struct {
fx.In
Lifecycle fx.Lifecycle
Config *Config
Env env.Environment
Logger *zap.Logger
}
// Register debug.
func Register(params RegisterParams) {
if !params.Env.IsDevelopment() {
return
}
m := mux(params.Lifecycle, params.Config, params.Logger)
// Register statsviz.
statsviz.Register(m)
// Register pprof.
m.HandleFunc("/debug/pprof/", pprof.Index)
m.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
m.HandleFunc("/debug/pprof/profile", pprof.Profile)
m.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
m.HandleFunc("/debug/pprof/trace", pprof.Trace)
// Register psutil.
m.HandleFunc("/debug/psutil", psutil)
}