panic

package
v0.0.0-...-891d2fd Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause, BSD-3-Clause Imports: 2 Imported by: 0

README

panic

GoDoc

This package implements a request handler for incoming http requests. It allows to specify what should be done by the program in case a panic occurs during the request handling.

Usage recommendation

It is recommended for this request handler to be registered early. Most chains of request handlers should end up calling it in order to handle any potential panics they could have triggered.

We remind the programmer that request handlers are called in the reverse order of their registration/linking, i.e. last gets executed first.

How to use it?

The handler is implemented as follows:

type Handler struct {
	Handle func(ctx execution.Context, w http.ResponseWriter, r *http.Request)
	Log    func(data ...interface{})
	next   xhttp.Handler
}

The Handle field shall be provided by the programmer. It implements the panic handling logic.

The Log field allows to provide a logging function, should the programmer feel the need to provide a way to record abnormal behaviour.

Dependencies

This package depends on:

License

BSD 3-clause

Documentation

Overview

Package panic defiens a panic handler that deals with panics occuring during the handling of a http request. It is in general route-agnostic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Handle func(msg interface{}, w http.ResponseWriter, r *http.Request)
	// contains filtered or unexported fields
}

Handler allows for the registration of a panic handling function.

func NewHandler

func NewHandler(handler func(msg interface{}, w http.ResponseWriter, r *http.Request)) Handler

NewHandler return an object used to take care of panics stemming from the request handling process accomodated by a downstrean chain of registered request handlers.

Link enables the linking of a xhttp.Handler. The linked object holds the handling logic for the http request.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles the servicing of incoming http requests.

Jump to

Keyboard shortcuts

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