Fields for BaseCaptcha are made private. NewBaseCaptcha() constructor added.
This commit is contained in:
parent
7737c360d0
commit
a2bcff84d8
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user