Pprof Middleware
The Pprof middleware for Fiber provides runtime profiling data in the expected format for the pprof visualization tool through its HTTP server. Typically, this package is imported only when registering HTTP handlers. The handling paths all start with /debug/pprof/.
Signature
func New() fiber.Handler
Example
Import the middleware package as part of the Fiber web framework
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/pprof"
)
After initializing the Fiber application, you can use the following possibilities:
// Initialize with default configuration
app.Use(pprof.New())
// Or extend your configuration for customization
// For example, in a system with multiple entry points, it is common to add a URL prefix, such as:
app.Use(pprof.New(pprof.Config{Prefix: "/endpoint-prefix"}))
// This prefix will be added to the default path "/debug/pprof/", forming the URL "/endpoint-prefix/debug/pprof/".
Configuration
Property | Type | Description | Default Value |
---|---|---|---|
Next | func(*fiber.Ctx) bool |
Next defines a function to skip this middleware when the function returns true. | nil |
Prefix | string |
Prefix defines the URL prefix to be added before "/debug/pprof". Note that it should start with a forward slash (but not end with one). Example: "/federated-fiber" | "" |
Default Configuration
var ConfigDefault = Config{
Next: nil,
}