Skip to content

Commit

Permalink
feat(debug): add debug package for custom debugging endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjun827 committed Nov 3, 2023
1 parent 39b99fb commit 55f5b1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/services/thoughts-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/ardanlabs/conf/v3"
"github.com/youngjun827/thoughts/business/web/v1/debug"
"github.com/youngjun827/thoughts/foundation/logger"
)

Expand Down Expand Up @@ -98,7 +99,7 @@ func run(ctx context.Context, log *logger.Logger) error {
go func() {
log.Info(ctx, "startup", "status", "debug v1 router started", "host", cfg.Web.DebugHost)

err := http.ListenAndServe(cfg.Web.DebugHost, http.DefaultServeMux)
err := http.ListenAndServe(cfg.Web.DebugHost, debug.Mux())
if err != nil {
log.Error(ctx, "shutdown", "status", "debug v1 router closed", "host", cfg.Web.DebugHost, "msg", err)
}
Expand Down
21 changes: 21 additions & 0 deletions business/web/v1/debug/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Package debug provides handler support for the debugging endpoints.
package debug

import (
"expvar"
"net/http"
"net/http/pprof"
)

func Mux() *http.ServeMux {
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)
mux.Handle("/debug/vars", expvar.Handler())

return mux
}

0 comments on commit 55f5b1e

Please sign in to comment.