inmemdb

package
v0.0.0-...-4f254db Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExpiry

func GetExpiry() time.Duration

func Image

func Image(id captcha.ID, style string) *image.Image

func IsSolved

func IsSolved(id captcha.ID) bool

func New

func New(data string, captcha captcha.Captcha) (captcha.Captcha, captcha.ID)

func Remove

func Remove(id captcha.ID)

func SetExpiry

func SetExpiry(expiry time.Duration)

func Solve

func Solve(id captcha.ID, answer captcha.Answer) bool

Types

type InMemoryCaptchaDB

type InMemoryCaptchaDB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemoryCaptchaDB implementation that lives in a memory (map).

func NewInMemoryCaptchaDB

func NewInMemoryCaptchaDB(expiry time.Duration) *InMemoryCaptchaDB

NewInMemoryCaptchaDB returns an initialised instance of an InMemoryCaptchaDB. An expiry is a scan interval for expired CAPTCHAs (if passed a longer one, resets to a default (captcha.DefaultExpiredScanInterval)).

func (*InMemoryCaptchaDB) GetExpiry

func (imcdb *InMemoryCaptchaDB) GetExpiry() time.Duration

GetExpiry returns an expiry for a CAPTCHA.

func (*InMemoryCaptchaDB) Image

func (imcdb *InMemoryCaptchaDB) Image(id captcha.ID, style string) *image.Image

Image returns a freshly generated image for a CAPTCHA with style if applicable.

func (*InMemoryCaptchaDB) IsSolved

func (imcdb *InMemoryCaptchaDB) IsSolved(id captcha.ID) bool

IsSolved checks if CAPTCHA was solved and removes it from a database.

func (*InMemoryCaptchaDB) New

func (imcdb *InMemoryCaptchaDB) New(data string, cptcha captcha.Captcha) (captcha.Captcha, captcha.ID)

New accepts a CAPTCHA instance, generates an ID and store it in a database. A data string is an additional random data used to generate an ID, e.g. an IP-address.

func (*InMemoryCaptchaDB) Remove

func (imcdb *InMemoryCaptchaDB) Remove(id captcha.ID)

Remove a CAPTCHA from a database.

func (*InMemoryCaptchaDB) SetExpiry

func (imcdb *InMemoryCaptchaDB) SetExpiry(expiry time.Duration)

SetExpiry changes an expiry for a CAPTCHA and a scan interval. Scan interval cannot be longer than a default, so if it is, then resets to a default.

func (*InMemoryCaptchaDB) Solve

func (imcdb *InMemoryCaptchaDB) Solve(id captcha.ID, answer captcha.Answer) bool

Solve compares given answer with a stored one and if failed deletes a CAPTCHA from database.

Jump to

Keyboard shortcuts

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