blob: c07a454995f936e39ed869ad3591772ee355e145 (
plain)
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
|
package debug
import (
"context"
"net/http"
"net/http/pprof"
)
// Server is a HTTP server for debugging.
type Server struct {
srv *http.Server
}
// NewServer creates new HTTP server for debugging.
func NewServer() Server {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
return Server{srv: &http.Server{Handler: mux}}
}
// Start debug server.
func (s *Server) Start(addr string) error {
s.srv.Addr = addr
return s.srv.ListenAndServe()
}
// Stop debug server.
func (s *Server) Stop(ctx context.Context) error {
return s.srv.Shutdown(ctx)
}
|