Fields for BaseCaptcha are made private. NewBaseCaptcha() constructor added.

This commit is contained in:
Alexander Andreev 2022-08-19 02:21:57 +04:00
parent 7737c360d0
commit a2bcff84d8
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
1 changed files with 16 additions and 10 deletions

View File

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