Refactor of db.go to change expiration and expire to expiry. ExpireInterval field renamed to ExpireIn.
This commit is contained in:
parent
2e3d41a628
commit
1dd070abd4
@ -13,23 +13,23 @@ var expiredScanInterval = 60 * time.Second
|
||||
|
||||
type ICaptchaDB interface {
|
||||
New(data string) (ICaptcha, ID)
|
||||
SetExpiration(expire time.Duration)
|
||||
SetExpiry(expiry time.Duration)
|
||||
Image(id ID) (*image.Image, error)
|
||||
Solve(id ID, answer Answer) (bool, error)
|
||||
IsSolved(id ID) bool
|
||||
GetExpireInterval() time.Duration
|
||||
GetExpiry() time.Duration
|
||||
}
|
||||
|
||||
type CaptchaDB struct {
|
||||
DB map[ID]ICaptcha
|
||||
ExpireInterval time.Duration
|
||||
ExpireIn time.Duration
|
||||
mut sync.Mutex
|
||||
}
|
||||
|
||||
// SetExpiration stores expire value and starts a goroutine
|
||||
// SetExpiry stores expire value and starts a goroutine
|
||||
// that checks for expired CAPTCHAs every minute.
|
||||
func (cdb *CaptchaDB) SetExpiration(expire time.Duration) {
|
||||
cdb.ExpireInterval = expire
|
||||
func (cdb *CaptchaDB) SetExpiry(expire time.Duration) {
|
||||
cdb.ExpireIn = expire
|
||||
if expire < expiredScanInterval {
|
||||
expiredScanInterval = expire
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (cdb *CaptchaDB) SetExpiration(expire time.Duration) {
|
||||
time.Sleep(sleepFor)
|
||||
|
||||
for id, captcha := range cdb.DB {
|
||||
if time.Now().Sub(captcha.Expire()) <= 0 {
|
||||
if time.Now().Sub(captcha.Expiry()) <= 0 {
|
||||
delete(cdb.DB, id)
|
||||
}
|
||||
}
|
||||
@ -104,5 +104,5 @@ func (cdb *CaptchaDB) IsSolved(id ID) (bool, error) {
|
||||
}
|
||||
|
||||
func (cdb *CaptchaDB) GetExpireInterval() time.Duration {
|
||||
return cdb.ExpireInterval
|
||||
return cdb.ExpireIn
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user