middleware

package
v0.0.0-...-f309447 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminMiddleware

func AdminMiddleware(userStore UserStoreForAdmin) func(http.Handler) http.Handler

AdminMiddleware is a middleware that checks if the authenticated user has admin role It must be used after AuthMiddleware as it depends on the email being set in context

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware adds CORS headers to allow cross-origin requests

func DeleteCarImages

func DeleteCarImages(ctx context.Context, imageURLs []string)

DeleteCarImages removes all images for a deleted car

func GetCarImages

func GetCarImages(ctx context.Context, carID string) []string

GetCarImages is a placeholder function for getting existing car images This should be implemented when you update the car store

func GetEmailFromContext

func GetEmailFromContext(ctx context.Context) (string, bool)

GetEmailFromContext extracts the email from the request context

func GetUserRoleFromContext

func GetUserRoleFromContext(ctx context.Context) (string, bool)

GetUserRoleFromContext extracts the user role from the request context

func ImageUploadMiddleware

func ImageUploadMiddleware(next http.Handler) http.Handler

ImageUploadMiddleware handles image uploads to Cloudinary

func MetricMiddleware

func MetricMiddleware(next http.Handler) http.Handler

func ValidateToken

func ValidateToken(tokenString string) (string, error)

ValidateToken validates a JWT token and returns the email (stored in Subject) if valid

Types

type UserStoreForAdmin

type UserStoreForAdmin interface {
	GetUserByEmail(ctx context.Context, email string) (models.User, error)
}

UserStoreForAdmin defines the minimal interface needed by AdminMiddleware

Jump to

Keyboard shortcuts

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