middleware

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: MIT Imports: 15 Imported by: 3

README

a collection of net/http middleware

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestID added in v0.3.1

func GetRequestID(r *http.Request) (string, bool)

GetRequestID fetches the unique request ID from a request.

Types

type Middleware added in v0.2.1

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

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) LogRequest added in v0.3.1

func (m *Middleware) LogRequest(r *http.Request, status int, latency time.Duration)

LogRequest will log a request with known response status and handler latency.

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) RequestID added in v0.3.1

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

RequestID provides setting unique IDs per request and adding a hook to the logger to append these to log entries using the request's context. This should be placed at the TOP of handler stack.

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
}

TimeoutResponseWriter wraps an http.ResponseWriter to add request timeout capabilities.

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