Moved Solve() to be in order of an interface. Reduced a comment for BaseCaptcha struct.

This commit is contained in:
Alexander Andreev 2022-08-19 02:11:06 +04:00
parent 0bd37dc5fa
commit b7ba27b613
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -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
}