From f35c16f837d311eb8962e3fa45dc5c4f88b0cecc Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 30 Jul 2022 15:33:34 +0400 Subject: [PATCH] CAPTCHA implementation changed to a new interface. And now composes from BaseCaptcha struct. --- internal/captcha/dwelling_captcha.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/internal/captcha/dwelling_captcha.go b/internal/captcha/dwelling_captcha.go index e2df229..9880208 100644 --- a/internal/captcha/dwelling_captcha.go +++ b/internal/captcha/dwelling_captcha.go @@ -15,16 +15,16 @@ const ( ) type DwellingCaptcha struct { - captcha.Captcha + captcha.BaseCaptcha } func NewDwellingCaptcha(expiry time.Duration) *DwellingCaptcha { return &DwellingCaptcha{ - Captcha: captcha.Captcha{ + BaseCaptcha: captcha.BaseCaptcha{ ExpireIn: captcha.ExpiryDate(expiry)}} } -func (c *DwellingCaptcha) generateImage(style string) *image.Image { +func (c *DwellingCaptcha) Image(style string) image.Image { isDark := style == "dark" ctx := gg.NewContext(dwImageWidth, dwImageHeight) @@ -67,14 +67,5 @@ func (c *DwellingCaptcha) generateImage(style string) *image.Image { ctx.Stroke() } - c.Image = ctx.Image() - return &c.Image -} - -func (c *DwellingCaptcha) GetImage(style string) *image.Image { - if c.Image == nil { - return c.generateImage(style) - } - - return &c.Image + return ctx.Image() }