middleware

package
v0.0.0-...-088cb74 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMiddlewares

func AddMiddlewares(h http.Handler, middlewares ...Middleware) http.Handler

AddMiddlewares will add all middlewares in the passed orter and return a handler which may be used for the http server. Since they're added in the order they're passed, they will be executed in the reverse order.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware represents a middleware function which will add a handler before the final http serve handler.

func Logger

func Logger(logger logrus.FieldLogger) Middleware

Logger creates a logger in a http.Handler for the HTTP server.

func PanicRecovery

func PanicRecovery(logger logrus.FieldLogger) Middleware

PanicRecovery ensures that panics are handled.

func Prometheus

func Prometheus() Middleware

Prometheus will add metrics for the request to prometheus.

func RateLimiter

func RateLimiter(interval time.Duration, size int) Middleware

RateLimiter is a middleware that rate limits requests.

type ResponseWriterWithInfo

type ResponseWriterWithInfo struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriterWithInfo is a response writer that can hold additional information which can help enrich code executed as middlewares.

func NewResponseWriter

func NewResponseWriter(r http.ResponseWriter) *ResponseWriterWithInfo

NewResponseWriter will convert the response writer to a *ResponseWriterWithInfo if it is one, otherwise wrap the response writer in such type.

func (*ResponseWriterWithInfo) WriteError

func (r *ResponseWriterWithInfo) WriteError(err error)

WriteError will store the error on the response writer.

func (*ResponseWriterWithInfo) WriteHeader

func (r *ResponseWriterWithInfo) WriteHeader(code int)

WriteHeader will write the header to the response witer and store the status that was written.

Jump to

Keyboard shortcuts

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