inmemdb

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 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 InMemoryDB

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

InMemoryDB implementation that lives in a memory (map).

func NewInMemoryDB

func NewInMemoryDB(expiry time.Duration) *InMemoryDB

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

func (*InMemoryDB) GetExpiry

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

GetExpiry returns an expiry for a CAPTCHA.

func (*InMemoryDB) Image

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

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

func (*InMemoryDB) IsSolved

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

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

func (*InMemoryDB) New

func (imcdb *InMemoryDB) 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 (*InMemoryDB) Remove

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

Remove a CAPTCHA from a database.

func (*InMemoryDB) SetExpiry

func (imcdb *InMemoryDB) 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 (*InMemoryDB) Solve

func (imcdb *InMemoryDB) 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