Documentation ¶
Index ¶
- func HasOneOfRole(roles []string, apiKey *models.ApiKey) bool
- func HasRole(role string, apiKey *models.ApiKey) bool
- func NewRateLimiter(cache *cache.Redis, apiKey *models.ApiKey) *rate_limiter.RateLimiter
- func ToApiKeyFromContext(ctx context.Context) (*models.ApiKey, bool)
- func WithAcl(api huma.API, dbAdapter db.Adapter, cache *cache.Redis) func(ctx huma.Context, next func(huma.Context))
- func WithLogger(ctx huma.Context, next func(huma.Context))
- func WithRateLimiter(api huma.API, cache *cache.Redis) func(ctx huma.Context, next func(huma.Context))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasOneOfRole ¶
HasOneOfRole checks if the user has permission to access the given method based on multiple roles
func NewRateLimiter ¶
func NewRateLimiter(cache *cache.Redis, apiKey *models.ApiKey) *rate_limiter.RateLimiter
NewRateLimiter creates a new rate limiter instance based on the API key's rate limit settings. It configures the rate limiter's capacity and refill duration using the Redis cache.
func WithAcl ¶
func WithAcl(api huma.API, dbAdapter db.Adapter, cache *cache.Redis) func(ctx huma.Context, next func(huma.Context))
WithAcl is a middleware function for API key authentication and authorization. It checks if the API key is provided, validates it against a cache or database, and ensures the key has the necessary permissions to proceed.
func WithLogger ¶
func WithLogger(ctx huma.Context, next func(huma.Context))
WithLogger is a middleware function that logs details about each HTTP request and response. It logs the HTTP method, URL, remote address, response status, and duration of the request processing.
func WithRateLimiter ¶
func WithRateLimiter(api huma.API, cache *cache.Redis) func(ctx huma.Context, next func(huma.Context))
WithRateLimiter is a middleware function that enforces rate limiting based on the provided API key. It uses a Redis-backed rate limiter to track and limit the number of requests.
Types ¶
This section is empty.