Documentation
¶
Overview ¶
Package context provides middleware utilities for managing request context and user authentication state.
Index ¶
- func ClearUserContext(c echo.Context)
- func GetCorrelationID(ctx context.Context) string
- func GetEmail(c echo.Context) (string, bool)
- func GetLogger(ctx context.Context) logging.Logger
- func GetRequestID(ctx context.Context) string
- func GetRole(c echo.Context) (string, bool)
- func GetUserID(c echo.Context) (string, bool)
- func IsAdmin(c echo.Context) bool
- func IsAuthenticated(c echo.Context) bool
- func SetEmail(c echo.Context, email string)
- func SetRole(c echo.Context, role string)
- func SetUserID(c echo.Context, userID string)
- type Key
- type Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearUserContext ¶
ClearUserContext clears all user-related data from context
func GetCorrelationID ¶
GetCorrelationID retrieves the correlation ID from context
func GetRequestID ¶
GetRequestID retrieves the request ID from context
func IsAuthenticated ¶
IsAuthenticated checks if the user is authenticated
Types ¶
type Key ¶
type Key string
Key represents a key in the context
const ( // RequestIDHeader is the HTTP header name for request ID RequestIDHeader = "X-Trace-Id" // RequestTimeout is the default timeout for request context RequestTimeout = 30 * time.Second // RequestIDKey is the context key for request ID RequestIDKey Key = "request_id" // CorrelationIDKey is the context key for correlation ID CorrelationIDKey Key = "correlation_id" // LoggerKey is the context key for logger LoggerKey Key = "logger" // UserIDKey is the context key for user ID UserIDKey Key = "user_id" // EmailKey is the context key for user email EmailKey Key = "email" // RoleKey is the context key for user role RoleKey Key = "role" // SessionKey is the context key for session SessionKey Key = "session" )
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware provides context handling for HTTP requests
func NewMiddleware ¶
func NewMiddleware(logger logging.Logger, requestTimeout time.Duration) *Middleware
NewMiddleware creates a new context middleware
func (*Middleware) WithContext ¶
func (m *Middleware) WithContext() echo.MiddlewareFunc
WithContext adds context to the request
Click to show internal directories.
Click to hide internal directories.