File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ package debug
2+
3+ import (
4+ "context"
5+ "net/http"
6+ "net/http/pprof"
7+ "sync"
8+
9+ "github.com/replicate/go/logging"
10+ )
11+
12+ var logger = logging .New ("debug" )
13+
14+ var defaultServeMux http.ServeMux
15+
16+ func init () {
17+ defaultServeMux .HandleFunc ("/debug/pprof/" , pprof .Index )
18+ defaultServeMux .HandleFunc ("/debug/pprof/cmdline" , pprof .Cmdline )
19+ defaultServeMux .HandleFunc ("/debug/pprof/profile" , pprof .Profile )
20+ defaultServeMux .HandleFunc ("/debug/pprof/symbol" , pprof .Symbol )
21+ defaultServeMux .HandleFunc ("/debug/pprof/trace" , pprof .Trace )
22+ }
23+
24+ type Server struct {
25+ Addr string
26+
27+ once sync.Once
28+ server * http.Server
29+ }
30+
31+ func (s * Server ) init () {
32+ s .server = & http.Server {
33+ Addr : s .Addr ,
34+ Handler : & defaultServeMux ,
35+ }
36+ }
37+
38+ func (s * Server ) ListenAndServe () error {
39+ s .once .Do (s .init )
40+
41+ logger .Sugar ().Infow ("starting debug http server" , "address" , s .Addr )
42+ return s .server .ListenAndServe ()
43+ }
44+
45+ func (s * Server ) Shutdown (ctx context.Context ) error {
46+ s .once .Do (s .init )
47+
48+ return s .server .Shutdown (ctx )
49+ }
You can’t perform that action at this time.
0 commit comments