otpmanagermdl

package
v1.2.17 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// keys for the entry object
	KEY_DATA       = "data"
	KEY_EXPIREDAT  = "expiredAt"
	KEY_EXPIRATION = "expiration"
)

Variables

View Source
var ErrInvalidDataType = errors.New("INVALID_DATA_Type")
View Source
var ErrOtpNotFound = errors.New("OTP_NOT_FOUND")

Functions

func DeleteOTP

func DeleteOTP(key string) error

// Delete removes the otp entry. If the key is not present, error `ErrOtpNotFound` will be thrown. Caller can ignore error if this is acceptable.

func Init

func Init(cache cachemdl.Cacher)

Init initializes otp manager with provided cache. Subsequent calls will not have any effect after first initialization.

func NewRedisEntry

func NewRedisEntry(entry Entry) string

NewRedisEntry prepares the entry for redis cache. This is required because redis accepts a byte array.

func Store

func Store(key string, entry Entry)

Store adds/ updates the entry against the provided key.

Types

type Entry

type Entry struct {
	Data       gjson.Result `json:"data,omitempty"`
	Expiration int64        `json:"expiration,omitempty"`
	ExpiredAT  int64        `json:"expiredAt,omitempty"`
}

Entry is a data to be stored against a key.

func GetOTP

func GetOTP(key string) (Entry, bool)

func NewOTPEntry

func NewOTPEntry(val gjson.Result, exp int64) Entry

NewEntry prepares the object required to store data in session.

The `exp` field interprets time in seconds. Ex. For 5 seconds, set `5`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳