From 916b85500d4ff24692bfc641a073cbc13a075541 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 19 Aug 2022 02:09:01 +0400 Subject: [PATCH] captchaDb is now of type CaptchaDB interface. Use a constructor for InMemoryCaptchaDB. A new captcha is now being created here instead of passed as an argument. --- internal/captcha/instance.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/captcha/instance.go b/internal/captcha/instance.go index 1440647..b695b52 100644 --- a/internal/captcha/instance.go +++ b/internal/captcha/instance.go @@ -6,15 +6,15 @@ import ( "time" ) -var captchaDb captcha.InMemoryCaptchaDB = captcha.InMemoryCaptchaDB{ - DB: make(map[captcha.ID]captcha.Captcha)} +var captchaDb captcha.CaptchaDB func Init(expiry time.Duration) { - captchaDb.SetExpiry(expiry) + captchaDb = captcha.NewInMemoryCaptchaDB(expiry) } -func New(data string, captcha captcha.Captcha) (captcha.Captcha, captcha.ID) { - return captchaDb.New(data, captcha) +func New(data string) (captcha.Captcha, captcha.ID) { + dc := NewDwellingCaptcha(captchaDb.GetExpiry()) + return captchaDb.New(data, dc) } func Image(id captcha.ID, style string) (*image.Image, error) {