rest_middlewares

package
v0.9.9-rc3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 17 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 WithCors

func WithCors(config options.Cors) func(ctx huma.Context, next func(huma.Context))

WithCors is a middleware function that sets CORS headers based on the provided configuration. It allows you to specify allowed origins, methods, headers, credentials, and max age.

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