summaryrefslogtreecommitdiff
path: root/internal/debug/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/debug/server.go')
-rw-r--r--internal/debug/server.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/debug/server.go b/internal/debug/server.go
new file mode 100644
index 00000000..c07a4549
--- /dev/null
+++ b/internal/debug/server.go
@@ -0,0 +1,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)
+}