recovery

package module
v0.0.0-...-05bd745 Latest Latest
Warning

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

Go to latest
Published: May 5, 2015 License: MIT Imports: 5 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Recovery

Recovery is a middleware for recovering from panic with interfaces func(next http.Handler) http.Handler and func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Example

package main

import (
    "github.com/vanng822/r2router"
    "github.com/vanng822/recovery"
    "net/http"
)

func main() {
    seefor := r2router.NewSeeforRouter()
    rec := recovery.NewRecovery()
    rec.PrintStack = true
    seefor.Before(rec.Handler)
	seefor.Get("/user/keys/:id", func(w http.ResponseWriter, r *http.Request, _ r2router.Params) {
		panic("This shouldn't crash Seefor")
	})
	
    http.ListenAndServe(":8080", seefor)
}

Documentation

Overview

Package recovery implements couple of middleware interfaces

package main

import (
	"github.com/vanng822/r2router"
	"github.com/vanng822/recovery"
	"net/http"
)

func main() {
	seefor := r2router.NewSeeforRouter()
	rec := recovery.NewRecovery()
	rec.PrintStack = true
	seefor.Before(rec.Handler)
	seefor.Get("/user/keys/:id", func(w http.ResponseWriter, r *http.Request, _ r2router.Params) {
		panic("Middleware panic")
	})

	http.ListenAndServe(":8080", seefor)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

type Recovery

type Recovery struct {
	Logger     Logger
	StackAll   bool
	StackSize  int
	PrintStack bool
}

func NewRecovery

func NewRecovery() *Recovery

func (*Recovery) Handler

func (rec *Recovery) Handler(next http.Handler) http.Handler

func (*Recovery) HandlerFuncWithNext

func (rec *Recovery) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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