跳到主要内容
版本:v2.x

Pprof

Fiber 的 Pprof 中间件,通过其 HTTP 服务器提供运行时性能分析数据,格式符合 pprof 可视化工具的要求。该包通常仅因注册其 HTTP 处理程序的副作用而被导入。处理的路径都以 /debug/pprof/ 开头。

签名

func New() fiber.Handler

示例

导入 Fiber Web 框架的一部分中间件包

import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/pprof"
)

初始化 Fiber 应用后,可以使用以下可能性

// Initialize default config
app.Use(pprof.New())

// Or extend your config for customization

// For example, in systems where you have multiple ingress endpoints, it is common to add a URL prefix, like so:
app.Use(pprof.New(pprof.Config{Prefix: "/endpoint-prefix"}))

// This prefix will be added to the default path of "/debug/pprof/", for a resulting URL of: "/endpoint-prefix/debug/pprof/".

配置

属性类型描述默认值
下一页func(*fiber.Ctx) boolNext 定义了一个函数,当返回 true 时跳过此中间件。nil
前缀stringPrefix 定义了一个添加到 "/debug/pprof" 前面的 URL 前缀。注意它应该以斜杠开头(但不以斜杠结尾)。示例: "/federated-fiber"""

默认配置

var ConfigDefault = Config{
Next: nil,
}