mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-02 22:00:16 +00:00
* internal: revert linting changes Changes to the internal package should not have been made in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5. * middleware/monitor: revert changes to exported field "ChartJSURL" This is a breaking change introduced in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5. * middleware/monitor: fix error checking Fix the errorenous error checking introduced in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5. * 🐛 Bug: Fix issues introduced in linting PR #2319 * 🐛 Bug: Fix issues introduced in linting PR #2319 * Bug: Fix issues introduced in linting PR #2319 --------- Co-authored-by: René Werner <rene@gofiber.io>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package recover //nolint:predeclared // TODO: Rename to some non-builtin
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// Config defines the config for middleware.
|
|
type Config struct {
|
|
// Next defines a function to skip this middleware when returned true.
|
|
//
|
|
// Optional. Default: nil
|
|
Next func(c *fiber.Ctx) bool
|
|
|
|
// EnableStackTrace enables handling stack trace
|
|
//
|
|
// Optional. Default: false
|
|
EnableStackTrace bool
|
|
|
|
// StackTraceHandler defines a function to handle stack trace
|
|
//
|
|
// Optional. Default: defaultStackTraceHandler
|
|
StackTraceHandler func(c *fiber.Ctx, e interface{})
|
|
}
|
|
|
|
// ConfigDefault is the default config
|
|
var ConfigDefault = Config{
|
|
Next: nil,
|
|
EnableStackTrace: false,
|
|
StackTraceHandler: defaultStackTraceHandler,
|
|
}
|
|
|
|
// Helper function to set default values
|
|
func configDefault(config ...Config) Config {
|
|
// Return default config if nothing provided
|
|
if len(config) < 1 {
|
|
return ConfigDefault
|
|
}
|
|
|
|
// Override default config
|
|
cfg := config[0]
|
|
|
|
if cfg.EnableStackTrace && cfg.StackTraceHandler == nil {
|
|
cfg.StackTraceHandler = defaultStackTraceHandler
|
|
}
|
|
|
|
return cfg
|
|
}
|