-
Notifications
You must be signed in to change notification settings - Fork 34
/
pprof.go
44 lines (40 loc) · 844 Bytes
/
pprof.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
43
44
package mws
import (
"net/http"
"net/http/pprof"
"strings"
)
func PProfHandler(enabled bool) func(handler http.Handler) http.Handler {
return func(handler http.Handler) http.Handler {
return &pprofHandler{
enabled: enabled,
next: handler,
}
}
}
type pprofHandler struct {
enabled bool
next http.Handler
}
func (h *pprofHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if h.enabled && strings.HasPrefix(req.URL.Path, "/debug/pprof") {
switch req.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(rw, req)
return
case "/debug/pprof/profile":
pprof.Profile(rw, req)
return
case "/debug/pprof/symbol":
pprof.Symbol(rw, req)
return
case "/debug/pprof/trace":
pprof.Trace(rw, req)
return
default:
pprof.Index(rw, req)
return
}
}
h.next.ServeHTTP(rw, req)
}