middleware

package
v0.0.0-...-cebead6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextValueMiddleware

func ContextValueMiddleware(key ContextKey, val interface{}) func(http.Handler) http.Handler

ContextValueMiddleware is a convenience function which stores a static value in the request context using the given contextKey.

func ExtractLogger

func ExtractLogger(ctx context.Context) *slog.Logger

func ExtractRequestID

func ExtractRequestID(ctx context.Context) string

func InjectLogger

func InjectLogger(logger *slog.Logger) func(http.Handler) http.Handler

func InjectRequestID

func InjectRequestID(next http.Handler) http.Handler

func Recoverer

func Recoverer(next http.Handler) http.Handler

func RequestLogger

func RequestLogger(next http.Handler) http.Handler

func UpdateLogger

func UpdateLogger(r *http.Request, logger *slog.Logger) *http.Request

Types

type Chain

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

func NewChain

func NewChain(middlewares ...Constructor) Chain

func (Chain) Then

func (c Chain) Then(fn http.HandlerFunc) http.Handler

type Constructor

type Constructor = func(http.Handler) http.Handler

type ContextKey

type ContextKey string
const CurrentUserContextKey ContextKey = "CurrentUser"

func (ContextKey) String

func (c ContextKey) String() string

type WrapResponseWriter

type WrapResponseWriter interface {
	http.ResponseWriter

	// Status returns the HTTP status of the request, or 0 if one has not
	// yet been sent.
	Status() int

	// BytesWritten returns the total number of bytes sent to the client.
	BytesWritten() int

	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.

func NewWrapResponseWriter

func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter

NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to introspect various information about the response.

Jump to

Keyboard shortcuts

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