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
38
|
package middleware
import (
"net/http"
"net/http/pprof"
"github.com/labstack/echo/v4"
)
func RegisterPprof(e *echo.Echo, prefixOptions ...string) {
prefix := "/debug/pprof"
if len(prefixOptions) > 0 {
prefix = prefixOptions[0]
}
prefixRouter := e.Group(prefix)
{
prefixRouter.GET("/", pprofAdapter(pprof.Index))
prefixRouter.GET("/allocs", pprofAdapter(pprof.Handler("allocs").ServeHTTP))
prefixRouter.GET("/block", pprofAdapter(pprof.Handler("block").ServeHTTP))
prefixRouter.GET("/cmdline", pprofAdapter(pprof.Cmdline))
prefixRouter.GET("/goroutine", pprofAdapter(pprof.Handler("goroutine").ServeHTTP))
prefixRouter.GET("/heap", pprofAdapter(pprof.Handler("heap").ServeHTTP))
prefixRouter.GET("/mutex", pprofAdapter(pprof.Handler("mutex").ServeHTTP))
prefixRouter.GET("/profile", pprofAdapter(pprof.Profile))
prefixRouter.POST("/symbol", pprofAdapter(pprof.Symbol))
prefixRouter.GET("/symbol", pprofAdapter(pprof.Symbol))
prefixRouter.GET("/threadcreate", pprofAdapter(pprof.Handler("threadcreate").ServeHTTP))
prefixRouter.GET("/trace", pprofAdapter(pprof.Trace))
}
}
func pprofAdapter(h http.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
h.ServeHTTP(c.Response().Writer, c.Request())
return nil
}
}
|