recovery

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 3 Imported by: 0

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 类型的实现。方便 New 在调试期间将函数的调用信息输出到 w。

Types

type RecoverFunc

type RecoverFunc func(w http.ResponseWriter, msg interface{})

RecoverFunc 错误处理函数。Recovery 需要此函数作为出错时的处理。

msg 为输出的错误信息,可能是任意类型的数据,一般为从 recover() 返回的数据。

Directories

Path Synopsis
Package errorhandler 提供自定义错误处理功能 net/http 包中对于错误的处理是通过 http.Error() 进行的, 我们无法直接修改该方法,实现自定义的错误处理功能。
Package errorhandler 提供自定义错误处理功能 net/http 包中对于错误的处理是通过 http.Error() 进行的, 我们无法直接修改该方法,实现自定义的错误处理功能。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL