Pprof Middleware

Table of contents

  1. Register middleware
  2. Endpoints
  3. How it works
  4. Production note

Vox provides an optional middleware package for Go’s built-in pprof endpoints.

Register middleware

package main

import (
	"github.com/aisk/vox"
	"github.com/aisk/vox/middlewares/pprof"
)

func main() {
	app := vox.New()
	app.Use(pprof.Middleware)

	app.Get("/", func(ctx *vox.Context, req *vox.Request, res *vox.Response) {
		res.Body = "Hello, World!"
	})

	app.Run("localhost:3000")
}

Endpoints

After registering the middleware, these pprof paths are available:

  • /debug/pprof
  • /debug/pprof/cmdline
  • /debug/pprof/profile
  • /debug/pprof/symbol
  • /debug/pprof/trace

How it works

For pprof paths, the middleware sets res.DontRespond = true and writes directly via the raw http.ResponseWriter.

Production note

pprof endpoints can expose runtime and performance details. In production, enable them only for trusted networks, or protect them with authentication/authorization middleware.


Copyright © 2016-2020 aisk. Distributed by an MIT license.

This site uses Just the Docs, a documentation theme for Jekyll.