Documentation
¶
Overview ¶
Package pprof exposes Go runtime profiling endpoints on a Gin engine via github.com/gin-contrib/pprof. Import this package only in services that require profiling — importing it registers pprof handlers as a side effect.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Mount ¶
Mount registers pprof profiling endpoints on the provided Gin engine. Each handler is a native Gin route, so all Gin middleware (auth, rate-limit, etc.) applies cleanly.
Two prefix groups are registered:
- /debug/pprof/* — standard Go pprof path for direct access
- <path>/admin/pprof/* — API-gateway-friendly alias; <path> is the gateway prefix forwarded to this service (e.g. "/api/v1")
Example ¶
ExampleMount shows how to register pprof endpoints on a Gin engine. Mount registers two sets of routes:
- /debug/pprof/* — standard Go pprof path
- <path>/admin/pprof/* — API-gateway-friendly alias
Import this package only in services that require profiling.
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/gin-gonic/gin"
libgin "github.com/phcp-tech/common-library-golang/gin"
libpprof "github.com/phcp-tech/common-library-golang/gin/pprof"
)
func main() {
gin.SetMode(gin.TestMode)
router := libgin.InitGin(nil)
libpprof.Mount(router, "/api/v1")
// Standard pprof index is reachable at /debug/pprof/.
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/debug/pprof/", nil)
router.ServeHTTP(w, req)
fmt.Println(w.Code)
// API-gateway alias is also reachable.
w2 := httptest.NewRecorder()
req2 := httptest.NewRequest(http.MethodGet, "/api/v1/admin/pprof/", nil)
router.ServeHTTP(w2, req2)
fmt.Println(w2.Code)
}
Output: 200 200
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.