rest_middlewares

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasOneOfRole

func HasOneOfRole(roles []string, apiKey *models.ApiKey) bool

HasOneOfRole checks if the user has permission to access the given method based on multiple roles

func HasRole

func HasRole(role string, apiKey *models.ApiKey) bool

HasRole checks if the user has permission to access the given method

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 ToApiKeyFromContext

func ToApiKeyFromContext(ctx context.Context) (*models.ApiKey, bool)

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.

Jump to

Keyboard shortcuts

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