代码拉取完成,页面将自动刷新
同步操作将从 andeyalee/lessgo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package lessgo
import (
"fmt"
"runtime"
"github.com/lessgo/lessgo/logs/color"
)
type (
// RecoverConfig defines the config for recover middleware.
RecoverConfig struct {
// StackSize is the stack size to be printed.
// Optional with default value as 4k.
StackSize int
// DisableStackAll disables formatting stack traces of all other goroutines
// into buffer after the trace for the current goroutine.
// Optional with default value as false.
DisableStackAll bool
// DisablePrintStack disables printing stack trace.
// Optional with default value as false.
DisablePrintStack bool
}
)
var (
// DefaultRecoverConfig is the default recover middleware config.
DefaultRecoverConfig = RecoverConfig{
StackSize: 4 << 10, // 4 KB
DisableStackAll: false,
DisablePrintStack: false,
}
)
// Recover returns a middleware which recovers from panics anywhere in the chain
// and handles the control to the centralized HTTPErrorHandler.
func Recover() MiddlewareFunc {
return RecoverWithConfig(DefaultRecoverConfig)
}
// RecoverWithConfig returns a recover middleware from config.
// See `Recover()`.
func RecoverWithConfig(config RecoverConfig) MiddlewareFunc {
// Defaults
if config.StackSize == 0 {
config.StackSize = DefaultRecoverConfig.StackSize
}
return func(next HandlerFunc) HandlerFunc {
return func(c Context) error {
defer func() {
if r := recover(); r != nil {
var err error
switch r := r.(type) {
case error:
err = r
default:
err = fmt.Errorf("%v", r)
}
stack := make([]byte, config.StackSize)
length := runtime.Stack(stack, !config.DisableStackAll)
if !config.DisablePrintStack {
c.Logger().Error("[%s] %s %s", color.Red("PANIC RECOVER"), err, stack[:length])
}
c.Error(err)
}
}()
return next(c)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。