servermw

package
v0.0.0-...-2029fad Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

Log returns a middleware that injects a logger into the request context. It uses the trace from the context as a prefix, if it exists.

func RecordResponse

func RecordResponse(h http.Handler) http.HandlerFunc

RecordResponse returns a middleware that records the response status code and total bytes written to the response.

func Recovery

func Recovery(h http.Handler) http.HandlerFunc

Recovery returns a middleware that recovers from panics, writing a 500 status code and "internal server error" message to the response, and logging the panic and associated stack trace.

func Trace

func Trace(h http.Handler) http.HandlerFunc

Trace returns a middleware that inject a trace into the request context, picking uo the trace id from the request header if it exists, or generating a new one if it doesn't.

Types

type RecordingResponseWriter

type RecordingResponseWriter struct {
	// underlying response writer
	RW         http.ResponseWriter
	StatusCode int // first status code written to the response writer
	Bytes      int // total bytes written
}

RecordingResponseWriter is an http.ResponseWriter that keeps track of the status code and total body bytes written to it

func (*RecordingResponseWriter) Header

func (w *RecordingResponseWriter) Header() http.Header

Header just returns the underlying response writer's header.

func (*RecordingResponseWriter) Write

func (w *RecordingResponseWriter) Write(b []byte) (int, error)

Write writes the given bytes to the undelying response writer, setting the status code to 200 if it hasn't been set already.

func (*RecordingResponseWriter) WriteHeader

func (w *RecordingResponseWriter) WriteHeader(statusCode int)

WriteHeader sets the status code, if it hasn't been set already.

Jump to

Keyboard shortcuts

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