middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPanic = errors.New("panic")

ErrPanic is used when capturing a panic and wrapping it as an error. This error is never returned directly. You can test if an error is caused by a panic using the errors package:

if errors.Is(err, ErrPanic) {
   // do something
}

Functions

This section is empty.

Types

type StandardMiddleware

type StandardMiddleware func(*bottleneck.Context, bottleneck.Next) error

StandardMiddleware is the standard function signature for middleware using the base context type.

func Compress

func Compress() StandardMiddleware

Compress creates a middleware that compresses the response, if the request accepts it.

Supported encodings are: gzip and deflate.

The weighted preference of accepted encodings is not respected. The first supported encoding in the list of accepted encodings will be applied.

func Limit

func Limit(size int64) StandardMiddleware

Limit creates a middleware that returns an error when a request body is larger than size.

func Logger

func Logger() StandardMiddleware

Logger creates a middleware that logs requests after the handler is called.

If an error occurs the status is set to 500 or the status of a bottleneck.Error respectively. Logger should be added before Recover to log panics.

func Recover

func Recover() StandardMiddleware

Recover creates a middleware that recovers from panics and wraps them as errors.

The resulting error embeds ErrPanic and has the form "panic: {panic value}\n{stacktrace}".

Jump to

Keyboard shortcuts

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