From 1dd070abd42bf7a7687617656b6753e59dc18388 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 26 Jun 2022 20:49:43 +0400 Subject: [PATCH] Refactor of db.go to change expiration and expire to expiry. ExpireInterval field renamed to ExpireIn. --- internal/captcha/db.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/captcha/db.go b/internal/captcha/db.go index 89aecce..b1f7f4a 100644 --- a/internal/captcha/db.go +++ b/internal/captcha/db.go @@ -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 - mut sync.Mutex + DB map[ID]ICaptcha + 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 }