From 96e8cf0c9741966dcc15301992693e36df11fcf5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 26 Jun 2022 22:02:38 +0400 Subject: [PATCH] Methods Solve, GetAnswer, IsSolved, and Expiry could be implemented once for a base Captcha struct. But GetImage and generateImage methods should be implemented by all structs that compose with base Captcha struct. --- internal/captcha/captcha.go | 17 +++++++++++++++++ internal/captcha/dwelling_captcha.go | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/internal/captcha/captcha.go b/internal/captcha/captcha.go index 7e9387f..886dbdd 100644 --- a/internal/captcha/captcha.go +++ b/internal/captcha/captcha.go @@ -34,6 +34,23 @@ type Captcha struct { ExpireIn time.Time } +func (c *Captcha) Solve(answer Answer) bool { + c.Solved = c.Answer == answer + return c.Solved +} + +func (c *Captcha) GetAnswer() Answer { + return c.Answer +} + +func (c *Captcha) IsSolved() bool { + return c.Solved +} + +func (c *Captcha) Expiry() time.Time { + return c.ExpireIn +} + func GenerateAnswer() Answer { ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer)) return (Answer(ans.String())) diff --git a/internal/captcha/dwelling_captcha.go b/internal/captcha/dwelling_captcha.go index 59055db..e3e8f7d 100644 --- a/internal/captcha/dwelling_captcha.go +++ b/internal/captcha/dwelling_captcha.go @@ -72,20 +72,3 @@ func (c *DwellingCaptcha) GetImage() *image.Image { return &c.Image } - -func (c *DwellingCaptcha) Solve(answer Answer) bool { - c.Solved = c.Answer == answer - return c.Solved -} - -func (c *DwellingCaptcha) GetAnswer() Answer { - return c.Answer -} - -func (c *DwellingCaptcha) IsSolved() bool { - return c.Solved -} - -func (c *DwellingCaptcha) Expiry() time.Time { - return c.ExpireIn -}