Home / Function/ New() — fiber Function Reference

New() — fiber Function Reference

Architecture documentation for the New() function in pprof.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  832cb442_9942_72f1_466c_b842e51edfa0["New()"]
  aa182fbd_7ebc_9ff7_0ebb_4d64d2d4034e["pprof.go"]
  832cb442_9942_72f1_466c_b842e51edfa0 -->|defined in| aa182fbd_7ebc_9ff7_0ebb_4d64d2d4034e
  style 832cb442_9942_72f1_466c_b842e51edfa0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/pprof/pprof.go lines 14–85

func New(config ...Config) fiber.Handler {
	// Set default config
	cfg := configDefault(config...)

	// Set pprof adaptors
	var (
		pprofIndex        = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Index)
		pprofCmdline      = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Cmdline)
		pprofProfile      = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Profile)
		pprofSymbol       = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Symbol)
		pprofTrace        = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Trace)
		pprofAllocs       = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler("allocs").ServeHTTP)
		pprofBlock        = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler("block").ServeHTTP)
		pprofGoroutine    = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler("goroutine").ServeHTTP)
		pprofHeap         = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler("heap").ServeHTTP)
		pprofMutex        = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler("mutex").ServeHTTP)
		pprofThreadcreate = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler("threadcreate").ServeHTTP)
	)

	// Construct actual prefix
	prefix := cfg.Prefix + "/debug/pprof"

	// Return new handler
	return func(c fiber.Ctx) error {
		// Don't execute middleware if Next returns true
		if cfg.Next != nil && cfg.Next(c) {
			return c.Next()
		}

		path := c.Path()
		// We are only interested in /debug/pprof routes
		path, found := strings.CutPrefix(path, prefix)
		if !found {
			return c.Next()
		}
		// Switch on trimmed path against constant strings
		switch path {
		case "/":
			pprofIndex(c.RequestCtx())
		case "/cmdline":
			pprofCmdline(c.RequestCtx())
		case "/profile":
			pprofProfile(c.RequestCtx())
		case "/symbol":
			pprofSymbol(c.RequestCtx())
		case "/trace":
			pprofTrace(c.RequestCtx())
		case "/allocs":
			pprofAllocs(c.RequestCtx())
		case "/block":
			pprofBlock(c.RequestCtx())
		case "/goroutine":
			pprofGoroutine(c.RequestCtx())
		case "/heap":
			pprofHeap(c.RequestCtx())
		case "/mutex":
			pprofMutex(c.RequestCtx())
		case "/threadcreate":
			pprofThreadcreate(c.RequestCtx())
		default:
			// pprof index only works with trailing slash
			if strings.HasSuffix(path, "/") {
				path = utils.TrimRight(path, '/')
			} else {
				path = prefix + "/"
			}

			return c.Redirect().To(path)
		}
		return nil
	}
}

Domain

Subdomains

Frequently Asked Questions

What does New() do?
New() is a function in the fiber codebase, defined in middleware/pprof/pprof.go.
Where is New() defined?
New() is defined in middleware/pprof/pprof.go at line 14.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free