Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Put stores a value in the cache with the specified key and optional TTL (time-to-live). // If ttl is nil, the value is stored indefinitely. // Returns an error if the operation fails. Put(key string, value any, ttl *time.Duration) error // Update updates the value of an existing key in the cache. // Returns true if the key exists, and an error if the operation fails. Update(key string, value any) (bool, error) // PutOrUpdate stores a value in the cache with the specified key and TTL. // If the key exists, the existing TTL is preserved. // If ttl is nil, the value is stored indefinitely. // Returns an error if the operation fails. PutOrUpdate(key string, value any, ttl *time.Duration) error // Get retrieves the value associated with the specified key from the cache. // Returns the value and an error if the operation fails. Get(key string) (any, error) // Pull retrieves the value associated with the specified key and removes it from the cache. // Returns the value and an error if the operation fails. Pull(key string) (any, error) // Cast retrieves the value associated with the specified key and casts it to a cast.Caster. // Returns the casted value and an error if the operation fails. Cast(key string) (cast.Caster, error) // Exists checks whether a key exists in the cache. // Returns true if the key exists, and an error if the operation fails. Exists(key string) (bool, error) // Forget removes the value associated with the specified key from the cache. // Returns an error if the operation fails. Forget(key string) error // TTL retrieves the time-to-live (TTL) of the value associated with the specified key. // Returns the TTL and an error if the operation fails. TTL(key string) (time.Duration, error) // Increment increases the integer value of the specified key by the given amount. // Returns true if the key exists, and an error if the operation fails. Increment(key string, value int64) (bool, error) // Decrement decreases the integer value of the specified key by the given amount. // Returns true if the key exists, and an error if the operation fails. Decrement(key string, value int64) (bool, error) // IncrementFloat increases the float value of the specified key by the given amount. // Returns true if the key exists, and an error if the operation fails. IncrementFloat(key string, value float64) (bool, error) // DecrementFloat decreases the float value of the specified key by the given amount. // Returns true if the key exists, and an error if the operation fails. DecrementFloat(key string, value float64) (bool, error) }
Cache provides a nil-safe interface for caching operations.
func NewMemoryCache ¶
func NewMemoryCache() Cache
NewMemoryCache creates and returns a new in-memory cache instance.
func NewRedisCache ¶
NewRedisCache creates a new Redis cache instance with a given prefix and Redis client.
type Queue ¶
type Queue interface { // Push adds a value to the end of the queue. // Returns an error if the operation fails. Push(value any) error // Pull retrieves and removes the first item from the queue. // Returns the value and an error if the operation fails. Pull() (any, error) // Pop retrieves and removes the last item from the queue. // Returns the value and an error if the operation fails. Pop() (any, error) // Cast retrieves and removes the first item from the queue, // casting it to a `cast.Caster` type. // Returns the `Caster` instance and an error if the operation fails. Cast() (cast.Caster, error) // Length returns the current number of items in the queue. // Returns the queue length and an error if the operation fails. Length() (int64, error) // Clear removes all items from the queue. Clear() error }
Queue represents a thread-safe, nil-safe queue interface. It provides methods to perform common queue operations.
func NewRedisQueue ¶
NewRedisQueue creates a new Redis queue instance.
type RateLimiter ¶
type RateLimiter interface { // Hit decrements the user's remaining attempts. // Returns an error if the operation fails. Hit() error // Lock locks the rate limiter, preventing further attempts. // Returns an error if the operation fails. Lock() error // Reset resets the rate limiter to its initial state. // Returns an error if the operation fails. Reset() error // Clear removes the rate limiter from the cache. // Returns an error if the operation fails. Clear() error // MustLock checks if the rate limiter should be locked. // Returns a boolean indicating the lock state and an error if the operation fails. MustLock() (bool, error) // TotalAttempts returns the total number of attempts made by the user. // Returns the total attempts and an error if the operation fails. TotalAttempts() (uint32, error) // RetriesLeft returns the number of remaining attempts for the user. // Returns the remaining attempts and an error if the operation fails. RetriesLeft() (uint32, error) // AvailableIn returns the time duration until the rate limiter unlocks. // Returns the time until unlock and an error if the operation fails. AvailableIn() (time.Duration, error) }
RateLimiter defines the interface for a rate limiter.
func NewRateLimiter ¶
NewRateLimiter creates and returns a new rate limiter instance.
type VerificationCode ¶
type VerificationCode interface { // Set stores the verification code in the cache. Set(code string) error // Generate creates a random numeric code of the specified length and stores it in the cache. Generate(count uint) (string, error) // Clear removes the verification code from the cache. Clear() error // Get retrieves the verification code from the cache. Get() (string, error) // Validate checks if the provided code matches the stored verification code. Validate(code string) (bool, error) // Exists checks if the verification code exists in the cache. Exists() (bool, error) // TTL retrieves the time-to-live (TTL) of the verification code in the cache. TTL() (time.Duration, error) }
VerificationCode defines the interface for managing verification codes in a cache.
func NewVerification ¶
func NewVerification(name string, maxAttempts uint32, ttl time.Duration, cache Cache) VerificationCode
NewVerification creates a new instance of the verification code.