From b7ba27b61382d495a02a1e6dd90a39a01a908d48 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 19 Aug 2022 02:11:06 +0400 Subject: [PATCH] Moved Solve() to be in order of an interface. Reduced a comment for BaseCaptcha struct. --- pkg/captcha/captcha.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 774df00..6e3b746 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -36,12 +36,7 @@ type Captcha interface { // BaseCaptcha is a base implementation of a CAPTCHA. // // All derivatives that embed this struct only need to -// implement GetImage() and generateImage() methods. -// And GetImage() could simply be copied. -// -// You need to do that because in Go there is no inheritance, -// and if you won't do that, calling a base GetImage -// method will call an empty base generateImage() method. +// implement Image() method. type BaseCaptcha struct { Answer Answer Solved bool @@ -52,11 +47,6 @@ func (c *BaseCaptcha) Image(style string) *image.Image { return nil } -func (c *BaseCaptcha) Solve(answer Answer) bool { - c.Solved = c.Answer == answer - return c.Solved -} - func (c *BaseCaptcha) GetAnswer() Answer { if c.Answer == "" { c.Answer = NewIntAnswer() @@ -64,6 +54,11 @@ func (c *BaseCaptcha) GetAnswer() Answer { return c.Answer } +func (c *BaseCaptcha) Solve(answer Answer) bool { + c.Solved = c.Answer == answer + return c.Solved +} + func (c *BaseCaptcha) IsSolved() bool { return c.Solved }