~poldi1405/gomod-recter

42490bc820e9d77cbffd274b6c812ffdce7c273b — Moritz Poldrack 1 year, 3 months ago b886524
add manhole functionality
1 files changed, 10 insertions(+), 0 deletions(-)

M internal/handler/manhole.go
M internal/handler/manhole.go => internal/handler/manhole.go +10 -0
@@ 2,9 2,12 @@ package handler

import (
	"fmt"
	"net/http"
	"net/http/pprof"
	"strings"

	"github.com/valyala/fasthttp"
	"github.com/valyala/fasthttp/fasthttpadaptor"
	"mpldr.codes/recter/project"
)



@@ 19,7 22,14 @@ func manholeHandler(ctx *fasthttp.RequestCtx) {
		for k, v := range projs {
			ctx.WriteString(fmt.Sprintf("%s:\n\t%#v\n\n", k, v))
		}
	case "pprof":
		fasthttpadaptor.NewFastHTTPHandlerFunc(pprofHandler)(ctx)
	default:
		handleError(fasthttp.StatusNotFound, ctx, nil)
	}
}

func pprofHandler(w http.ResponseWriter, r *http.Request) {
	r.URL.Path = "/debug/pprof" + strings.TrimPrefix(r.URL.Path, "/manhole/pprof")
	pprof.Index(w, r)
}