fault

package
v0.0.0-...-be655d7 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2016 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package fault provides a panic and error handler for the ozzo routing package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Recovery

func Recovery(log LogFunc) routing.Handler

Recovery returns a handler that handles panics and errors occurred while servicing an HTTP request.

The handler will recover from panics and render the recovered error or the error returned by a handler. If the error is not a routing.HTTPError, it will respond with http.StatusInternalServerError. Otherwise, it will use the status code of the HTTPError.

A log function can be provided to log a message whenever an error is handled. If nil, no message will be logged.

import (
    "log"
    "github.com/go-ozzo/ozzo-routing"
    "github.com/go-ozzo/ozzo-routing/fault"
)

r := routing.New()
r.Use(fault.Recovery(log.Printf))

Types

type LogFunc

type LogFunc func(format string, a ...interface{})

LogFunc logs a message using the given format and optional arguments. The usage of format and arguments is similar to that for fmt.Printf(). LogFunc should be thread safe.

Jump to

Keyboard shortcuts

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