recovery

package
v5.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 5 Imported by: 1

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 mux.RecoverFunc

RecoverFunc 错误处理函数

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

NOTE: 并不能保证 w 是空白的,可能有内容已经输出,所以有关报头的操作可能会不启作用。

github.com/issue9/mux/v5 用户可以直接使用其 mux.Recovery 处理会更好。

func ConsoleRecover

func ConsoleRecover(status int) RecoverFunc

ConsoleRecover 向控制台输出错误信息

status 表示向客户端输出的状态码。

func DefaultRecover

func DefaultRecover(status int) RecoverFunc

DefaultRecover RecoverFunc 的默认实现

向客户端输出 status 状态码,忽略其它任何信息。

func LogRecover

func LogRecover(l *log.Logger, status int) RecoverFunc

LogRecover 将错误信息输出到日志

l 为输出的日志;status 表示向客户端输出的状态码。

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