Moved Solve() to be in order of an interface. Reduced a comment for BaseCaptcha struct.
This commit is contained in:
parent
0bd37dc5fa
commit
b7ba27b613
@ -36,12 +36,7 @@ type Captcha interface {
|
|||||||
// BaseCaptcha is a base implementation of a CAPTCHA.
|
// BaseCaptcha is a base implementation of a CAPTCHA.
|
||||||
//
|
//
|
||||||
// All derivatives that embed this struct only need to
|
// All derivatives that embed this struct only need to
|
||||||
// implement GetImage() and generateImage() methods.
|
// implement Image() method.
|
||||||
// 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.
|
|
||||||
type BaseCaptcha struct {
|
type BaseCaptcha struct {
|
||||||
Answer Answer
|
Answer Answer
|
||||||
Solved bool
|
Solved bool
|
||||||
@ -52,11 +47,6 @@ func (c *BaseCaptcha) Image(style string) *image.Image {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BaseCaptcha) Solve(answer Answer) bool {
|
|
||||||
c.Solved = c.Answer == answer
|
|
||||||
return c.Solved
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseCaptcha) GetAnswer() Answer {
|
func (c *BaseCaptcha) GetAnswer() Answer {
|
||||||
if c.Answer == "" {
|
if c.Answer == "" {
|
||||||
c.Answer = NewIntAnswer()
|
c.Answer = NewIntAnswer()
|
||||||
@ -64,6 +54,11 @@ func (c *BaseCaptcha) GetAnswer() Answer {
|
|||||||
return c.Answer
|
return c.Answer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BaseCaptcha) Solve(answer Answer) bool {
|
||||||
|
c.Solved = c.Answer == answer
|
||||||
|
return c.Solved
|
||||||
|
}
|
||||||
|
|
||||||
func (c *BaseCaptcha) IsSolved() bool {
|
func (c *BaseCaptcha) IsSolved() bool {
|
||||||
return c.Solved
|
return c.Solved
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user