whfatal

package
Version: v1.0.0-...-3f30213 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package whfatal uses panics to make early termination of http.Handlers easier. No other webhelp package depends on or uses this one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Catch

func Catch(h http.Handler) http.Handler

Catch takes a Handler and returns a new one that works with Fatal, whfatal.Redirect, and whfatal.Error. Catch will also catch panics that are wherr.HTTPError errors. Catch should be placed *inside* a whlog.LogRequests handler, wherr.HandleWith handlers, and a few other handlers. Otherwise, the wrapper will be one of the things interrupted by Fatal calls.

func Error

func Error(err error)

Error is like wherr.Handle but panics so that all additional request processing terminates. Implemented with Fatal()

IMPORTANT: must be used with whfatal.Catch, or else the http.ResponseWriter won't be able to be obtained. Because this requires whfatal.Catch, if you're writing a library intended to be used by others, please avoid this and other Fatal* methods. If you are writing a library intended to be used by yourself, you should probably avoid these methods anyway.

func Fatal

func Fatal(handler func(w http.ResponseWriter, r *http.Request))

Fatal panics in a way that Catch understands to abort all additional request processing. Once request processing has been aborted, handler is called, if not nil. If handler doesn't write a response, a 500 will automatically be returned. whfatal.Error and whfatal.Redirect are implemented using this method.

IMPORTANT: must be used with whfatal.Catch, or else the http.ResponseWriter won't be able to be obtained. Because this requires whfatal.Catch, if you're writing a library intended to be used by others, please avoid this and other Fatal* methods. If you are writing a library intended to be used by yourself, you should probably avoid these methods anyway.

func Redirect

func Redirect(redirectTo string)

Redirect is like whredir.Redirect but panics so all additional request processing terminates. Implemented with Fatal().

IMPORTANT: must be used with whfatal.Catch, or else the http.ResponseWriter won't be able to be obtained. Because this requires whfatal.Catch, if you're writing a library intended to be used by others, please avoid this and other Fatal* methods. If you are writing a library intended to be used by yourself, you should probably avoid these methods anyway.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL