middleware

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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