recovery

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package recovery 提供了处理 panic 操作的中间件

recovery.RecoverFunc(func(w http.ResponseWriter, msg interface{}) {
    fmt.Printf("recovery: %s", msg)
}).MiddlewareFunc(func(w http.ResponseWriter, r *http.Request){
    panic("panic")
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RecoverFunc

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

RecoverFunc 错误处理函数

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

func DefaultRecoverFunc

func DefaultRecoverFunc() RecoverFunc

DefaultRecoverFunc RecoverFunc 的默认实现

为一个简单的 500 错误信息。不会输出 msg 参数的内容。

func TraceStack

func TraceStack() RecoverFunc

TraceStack 打印调用的堆栈信息的 RecoverFunc 实现

func (RecoverFunc) Middleware

func (rf RecoverFunc) Middleware(next http.Handler) http.Handler

Middleware 将当前中间件应用于 next

func (RecoverFunc) MiddlewareFunc

func (rf RecoverFunc) MiddlewareFunc(next func(w http.ResponseWriter, r *http.Request)) http.Handler

MiddlewareFunc 将当前中间件应用于 next

Jump to

Keyboard shortcuts

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