Skip to content

Conversation

@HeerakKashyap
Copy link

Add Pprof Middleware

Implements pprof middleware for runtime profiling as requested in #38.

What it does

Mounts Go's built-in pprof handlers under /debug/pprof (or custom prefix) so you can profile your app.

Usage

// Middleware approach
app.Use(middleware.Pprof())

// Or direct mounting (faster)
middleware.MountPprof(app)

// Custom prefix
middleware.MountPprof(app, "/profiling")

Available endpoints

  • /debug/pprof/ - Index page
  • /debug/pprof/profile - CPU profile
  • /debug/pprof/heap - Heap profile
  • /debug/pprof/goroutine - Goroutine profile
  • And more...

Security

Only enable in development. Consider adding auth for production use.

Closes #38

HeerakKashyap and others added 15 commits August 22, 2025 01:49
- Remove convenience_methods example (should be in separate repo)
- Added tests for edge cases in convenience methods
- Added tests for NoContent, Stream, StreamJSON edge cases
- Added tests for Clone, Finish, SetRequest, SetResponseWriter methods
- Added tests for Get with default values and Set method
- Improve coverage from 95.3% to 95.8%
- Resolve merge conflicts with upstream/main
- Remove duplicate BindJSON declarations (moved to bind.go)
- Add missing strings import to test file
- Keep convenience methods implementation
- Maintain test coverage improvements
- Add Redirect, File, NotFound, InternalServerError convenience methods
- Add BadRequest, Unauthorized, Forbidden, NoContent methods
- Add Stream, StreamJSON methods
- Add SetCookie, GetCookie, ClearCookie methods
- Add missing io import for Stream method
- Fix compilation errors in ratelimit_test.go
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Dmitri Meshin <[email protected]>
- Change from c.Forbidden() to c.Forbidden('file is a directory')
- Provide clear error message when attempting to serve a directory
- Maintain consistent error messaging across convenience methods
Co-authored-by: NewCapital.in <[email protected]>
Signed-off-by: HootingConjuror <[email protected]>
- Add Pprof middleware that mounts Go's built-in pprof handlers
- Add MountPprof function for direct route mounting (more efficient)
- Support configurable prefix (default: /debug/pprof)
- Include comprehensive tests and examples
- Add security considerations and usage documentation

Closes goflash#38
@codecov
Copy link

codecov bot commented Aug 27, 2025

Codecov Report

❌ Patch coverage is 65.71429% with 72 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
middleware/pprof.go 40.69% 51 Missing ⚠️
ctx/ctx.go 83.06% 21 Missing ⚠️

📢 Thoughts on this report? Let us know!

@HeerakKashyap
Copy link
Author

Hey @meshin-dev, do we need to pass the Codecov check? It’s only falling short by a small percentage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pprof exposure (Middlewares — P2)

2 participants