middleware

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateIntPathParam

func ValidateIntPathParam(r *http.Request, paramName string) (int, *util.ApiError)

ValidateIntPathParam validates and extracts an integer path parameter with enhanced error handling

Types

type ContextKey

type ContextKey string

ContextKey is used for storing request context in the request context

const RequestContextKey ContextKey = "request_context"

type ErrorHandlingMiddleware

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

ErrorHandlingMiddleware provides enhanced error handling and logging for REST handlers

func NewErrorHandlingMiddleware

func NewErrorHandlingMiddleware(logger *zap.SugaredLogger) *ErrorHandlingMiddleware

NewErrorHandlingMiddleware creates a new error handling middleware

func (*ErrorHandlingMiddleware) LogError

func (m *ErrorHandlingMiddleware) LogError(r *http.Request, err error, operation string)

LogError logs an error with request context for better debugging

func (*ErrorHandlingMiddleware) WithRequestContext

func (m *ErrorHandlingMiddleware) WithRequestContext(next http.Handler) http.Handler

WithRequestContext middleware adds request context for better error handling

type RequestContext

type RequestContext struct {
	RequestID    string
	StartTime    time.Time
	Method       string
	Path         string
	ResourceType string
	ResourceID   string
	UserID       int
}

RequestContext holds information about the current request for better error handling

func GetRequestContext

func GetRequestContext(r *http.Request) *RequestContext

GetRequestContext retrieves the request context from the HTTP request

Jump to

Keyboard shortcuts

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