context

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearUserContext

func ClearUserContext(c echo.Context)

ClearUserContext clears all user-related data from context

func GetCorrelationID

func GetCorrelationID(ctx context.Context) string

GetCorrelationID retrieves the correlation ID from context

func GetEmail

func GetEmail(c echo.Context) (string, bool)

GetEmail retrieves the user email from context

func GetLogger

func GetLogger(ctx context.Context) logging.Logger

GetLogger retrieves the logger from context

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the request ID from context

func GetRole

func GetRole(c echo.Context) (string, bool)

GetRole retrieves the user role from context

func GetUserID

func GetUserID(c echo.Context) (string, bool)

GetUserID retrieves the user ID from context

func IsAdmin

func IsAdmin(c echo.Context) bool

IsAdmin checks if the user is an admin

func IsAuthenticated

func IsAuthenticated(c echo.Context) bool

IsAuthenticated checks if the user is authenticated

func SetEmail

func SetEmail(c echo.Context, email string)

SetEmail sets the user email in context

func SetRole

func SetRole(c echo.Context, role string)

SetRole sets the user role in context

func SetUserID

func SetUserID(c echo.Context, userID string)

SetUserID sets the user ID in context

Types

type Key

type Key string

Key represents a key in the context

const (
	// Request context keys
	RequestIDHeader = "X-Trace-Id"
	RequestTimeout  = 30 * time.Second

	// Context keys
	RequestIDKey     Key = "request_id"
	CorrelationIDKey Key = "correlation_id"
	LoggerKey        Key = "logger"
	UserIDKey        Key = "user_id"
	EmailKey         Key = "email"
	RoleKey          Key = "role"
	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) *Middleware

NewMiddleware creates a new context middleware

func (*Middleware) WithContext

func (m *Middleware) WithContext() echo.MiddlewareFunc

WithContext adds context to the request

Jump to

Keyboard shortcuts

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