middleware

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 10 Imported by: 3

README

a collection of net/http middleware

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware added in v0.2.1

type Middleware struct {
	// Log is the log output for this Middleware.
	Log *logger.Logger
}

func (*Middleware) AddTimeout added in v0.3.0

AddTimeout wraps an http ResponseWriter and Request to add our own timeout tracking based on either "Request-Timeout", or fallback. Please note that due to the way the ResponseWriter is wrapped, it may mask underlying interface types. Cast to *TimeoutResponseWriter for original access.

func (*Middleware) HTTPError added in v0.2.1

func (m *Middleware) HTTPError(rw http.ResponseWriter, r *http.Request, msg string, code int, err error)

HTTPError handles responding to a client with an HTTP error code and logs the provided error.

func (*Middleware) Logger added in v0.2.1

func (m *Middleware) Logger(handler http.Handler) http.Handler

Logger adds request logging to the provided HTTP handler.

func (*Middleware) Recovery added in v0.2.1

func (m *Middleware) Recovery(handler http.Handler) http.Handler

Recovery adds panic recovery (and panic logging) to the provided HTTP handler.

func (*Middleware) Timeout added in v0.3.0

func (m *Middleware) Timeout(handler http.Handler, fallback time.Duration) http.Handler

Timeout adds user defined request timeouts to provided handler, either by "Request-Timeout" header or the given fallback value. Please note that this handler also provides logging so do not wrap within Middleware.Logger().

type TimeoutResponseWriter added in v0.3.0

type TimeoutResponseWriter struct {
	// contains filtered or unexported fields
}

func (*TimeoutResponseWriter) Cancel added in v0.3.0

func (rw *TimeoutResponseWriter) Cancel() bool

Cancel will attempt to cancel the timeout counter.

func (*TimeoutResponseWriter) Header added in v0.3.0

func (rw *TimeoutResponseWriter) Header() http.Header

Header implements http.ResponseWriter's .Header().

func (*TimeoutResponseWriter) ResponseWriter added in v0.3.0

func (rw *TimeoutResponseWriter) ResponseWriter() http.ResponseWriter

ResponseWriter returns access to the underlying http.ResponseWriter.

func (*TimeoutResponseWriter) Status added in v0.3.0

func (rw *TimeoutResponseWriter) Status() int

Status returns the set response status code.

func (*TimeoutResponseWriter) TimedOut added in v0.3.0

func (rw *TimeoutResponseWriter) TimedOut() bool

TimedOut returns whether this TimeoutResponseWriter has timed out.

func (*TimeoutResponseWriter) Write added in v0.3.0

func (rw *TimeoutResponseWriter) Write(b []byte) (int, error)

Write implements http.ResponseWriter's .Write().

func (*TimeoutResponseWriter) WriteHeader added in v0.3.0

func (rw *TimeoutResponseWriter) WriteHeader(status int)

WriteHeader implements http.ResponseWriter's .WriteHeader().

Jump to

Keyboard shortcuts

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