diff --git a/pkg/captcha/db.go b/pkg/captcha/db.go index b9fa5e7..c58da36 100644 --- a/pkg/captcha/db.go +++ b/pkg/captcha/db.go @@ -37,7 +37,7 @@ type ICaptchaDB interface { type CaptchaDB struct { DB map[ID]ICaptcha ExpireIn time.Duration - mut sync.Mutex + sync.Mutex } // SetExpiry stores expire value and starts a goroutine @@ -68,8 +68,8 @@ func (cdb *CaptchaDB) SetExpiry(expire time.Duration) { func (cdb *CaptchaDB) New(data string, captcha ICaptcha) (ICaptcha, ID) { id := NewID(data, captcha.GetAnswer()) - cdb.mut.Lock() - defer cdb.mut.Unlock() + cdb.Lock() + defer cdb.Unlock() cdb.DB[id] = captcha return captcha, id @@ -86,8 +86,8 @@ func (cdb *CaptchaDB) Image(id ID) (*image.Image, error) { // Solve compares given answer with a stored one and if failed // deletes a captcha from database. func (cdb *CaptchaDB) Solve(id ID, answer Answer) (bool, error) { - cdb.mut.Lock() - defer cdb.mut.Unlock() + cdb.Lock() + defer cdb.Unlock() if c, ok := cdb.DB[id]; ok { ok = c.Solve(answer) if !ok { @@ -101,8 +101,8 @@ func (cdb *CaptchaDB) Solve(id ID, answer Answer) (bool, error) { // IsSolved checks if captcha was solved and removes it // from a database. func (cdb *CaptchaDB) IsSolved(id ID) (bool, error) { - cdb.mut.Lock() - defer cdb.mut.Unlock() + cdb.Lock() + defer cdb.Unlock() if c, ok := cdb.DB[id]; ok { ok = c.IsSolved() delete(cdb.DB, id)