package service import ( "context" "errors" "net/http" "net/http/pprof" ) func startProfiler(ctx context.Context, addr string) { 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) server := &http.Server{ Addr: addr, Handler: mux, } go func() { <-ctx.Done() err := server.Shutdown(context.Background()) if err != nil { panic("pprof server shutdown failed: " + err.Error()) } }() go func() { err := server.ListenAndServe() if err != nil && !errors.Is(err, http.ErrServerClosed) { panic("pprof server failed: " + err.Error()) } }() }