diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 6e3b746..d1fcd20 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -38,9 +38,15 @@ type Captcha interface { // All derivatives that embed this struct only need to // implement Image() method. type BaseCaptcha struct { - Answer Answer - Solved bool - ExpireIn time.Time + answer Answer + solved bool + expireIn time.Time +} + +func NewBaseCaptcha(expiry time.Duration) *BaseCaptcha { + return &BaseCaptcha{ + expireIn: ExpiryDate(expiry), + } } func (c *BaseCaptcha) Image(style string) *image.Image { @@ -48,23 +54,23 @@ func (c *BaseCaptcha) Image(style string) *image.Image { } func (c *BaseCaptcha) GetAnswer() Answer { - if c.Answer == "" { - c.Answer = NewIntAnswer() + if c.answer == "" { + c.answer = NewIntAnswer() } - return c.Answer + return c.answer } func (c *BaseCaptcha) Solve(answer Answer) bool { - c.Solved = c.Answer == answer - return c.Solved + c.solved = c.answer == answer + return c.solved } func (c *BaseCaptcha) IsSolved() bool { - return c.Solved + return c.solved } func (c *BaseCaptcha) Expiry() time.Time { - return c.ExpireIn + return c.expireIn } func ExpiryDate(expiry time.Duration) time.Time {