Documentation
¶
Overview ¶
Package recovery 提供了处理 panic 操作的中间件。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(next http.Handler, rf RecoverFunc) http.Handler
New 声明一个处理 panic 操作的中间件。 next 参数中发生的 panic 将被截获并处理,不会再向上级反映。
当 next 参数为空时,将直接 panic。 rf 参数用于指定处理 panic 信息的函数,其原型为 RecoverFunc, 当将 rf 指定为 nil 时,将使用默认的处理函数,仅仅向客户端输出 500 的错误信息,没有具体内容。
func PrintDebug ¶
func PrintDebug(w http.ResponseWriter, msg interface{})
PrintDebug 是 RecoverFunc 类型的实现。方便 NewRecovery 在调试期间将函数的调用信息输出到 w。
Types ¶
type RecoverFunc ¶
type RecoverFunc func(w http.ResponseWriter, msg interface{})
RecoverFunc 错误处理函数。Recovery 需要此函数作为出错时的处理。
msg 为输出的错误信息,可能是任意类型的数据,一般为从 recover() 返回的数据。
Click to show internal directories.
Click to hide internal directories.