middleware

package
v0.0.0-...-ad8f1bd Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey ctxKeyRequestID = 0

RequestIDKey is the key that holds the unique request ID in a request context.

Variables

This section is empty.

Functions

func Dumper

func Dumper(w io.Writer) func(http.Handler) http.Handler

Dumper returns a debug middleware which prints detailed information about incoming requests and outgoing responses including all headers, parameters and bodies.

func GetReqID

func GetReqID(ctx context.Context) string

GetReqID returns a request ID from the given context if one is present. Returns the empty string if a request ID cannot be found.

func NewLogFormatter

func NewLogFormatter(logger *slog.Logger) middleware.LogFormatter

func RequestID

func RequestID(options ...RequestIDOption) func(http.Handler) http.Handler

RequestID is a middleware that injects a request ID into the context of each request.

Types

type LogEntry

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

LogEntry represents an individual log entry.

func (*LogEntry) Panic

func (l *LogEntry) Panic(v interface{}, stack []byte)

Panic prints the call stack for a panic.

func (*LogEntry) Write

func (l *LogEntry) Write(status, totalBytes int, _ http.Header, elapsed time.Duration, _ any)

Write constructs and writes the final log entry.

type LogFormatter

type LogFormatter func(r *http.Request) middleware.LogEntry

func (LogFormatter) NewLogEntry

func (l LogFormatter) NewLogEntry(r *http.Request) middleware.LogEntry

type RequestIDOption

type RequestIDOption func(*RequestIDOptions) *RequestIDOptions

func UseXRequestIDHeaderOption

func UseXRequestIDHeaderOption(f bool) RequestIDOption

func XRequestIDLimitOption

func XRequestIDLimitOption(limit int) RequestIDOption

type RequestIDOptions

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

func (*RequestIDOptions) UseRequestID

func (o *RequestIDOptions) UseRequestID() bool

Jump to

Keyboard shortcuts

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