Documentation
¶
Overview ¶
Package pprof provides a middleware that exposes Go runtime profiling data via the standard net/http/pprof handlers.
The middleware intercepts requests under a configurable prefix (default "/debug/pprof") and dispatches to the matching pprof handler. Non-matching requests pass through to the next handler with zero overhead.
Use New with an optional Config to mount the profiling endpoints:
server.Use(pprof.New())
Config.Prefix controls the URL prefix (default "/debug/pprof"). Config.AuthFunc gates access; the default restricts to loopback addresses (127.0.0.1 and ::1) using the raw TCP peer address — set a custom AuthFunc when running behind a reverse proxy. Config.Skip and Config.SkipPaths provide request-level bypass logic.
Documentation ¶
Full guides and examples: https://goceleris.dev/docs/observability
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(config ...Config) celeris.HandlerFunc
New creates a pprof middleware with the given config.
Example ¶
package main
import (
"github.com/goceleris/celeris"
"github.com/goceleris/celeris/middleware/pprof"
)
func main() {
server := celeris.New(celeris.Config{})
// Default config: loopback-only access at /debug/pprof.
server.Use(pprof.New())
}
Output:
Example (CustomPrefix) ¶
package main
import (
"github.com/goceleris/celeris"
"github.com/goceleris/celeris/middleware/pprof"
)
func main() {
server := celeris.New(celeris.Config{})
server.Use(pprof.New(pprof.Config{
Prefix: "/profiling",
}))
}
Output:
Example (PublicAccess) ¶
package main
import (
"github.com/goceleris/celeris"
"github.com/goceleris/celeris/middleware/pprof"
)
func main() {
server := celeris.New(celeris.Config{})
// Allow all clients (disable loopback-only restriction).
server.Use(pprof.New(pprof.Config{
AuthFunc: func(_ *celeris.Context) bool { return true },
}))
}
Output:
Example (TokenAuth) ¶
package main
import (
"os"
"github.com/goceleris/celeris"
"github.com/goceleris/celeris/middleware/pprof"
)
func main() {
server := celeris.New(celeris.Config{})
// Token-based authentication via environment variable.
server.Use(pprof.New(pprof.Config{
AuthFunc: func(c *celeris.Context) bool {
return c.Header("x-pprof-token") == os.Getenv("PPROF_TOKEN")
},
}))
}
Output:
Types ¶
type Config ¶
type Config struct {
// Skip defines a function to skip this middleware for certain requests.
Skip func(c *celeris.Context) bool
// SkipPaths lists full paths to bypass entirely (exact match).
// Only consulted for requests that match the prefix. Checked before
// authentication and handler dispatch.
SkipPaths []string
// Prefix is the URL path prefix for pprof endpoints.
// Default: "/debug/pprof".
Prefix string
// AuthFunc is an authentication check executed before any pprof endpoint.
// If it returns false, the middleware responds with 403 Forbidden.
// Default: allows only loopback IPs (127.0.0.1 and ::1).
// Set to func(*celeris.Context) bool { return true } to allow public access.
AuthFunc func(c *celeris.Context) bool
}
Config defines the pprof middleware configuration.