A function for generating an answer was transformed into a constructor with specified type of integer in its name. maxAnswer constant renamed to maxIntAnswer.
This commit is contained in:
parent
d7a04516e3
commit
18431e0001
@ -8,11 +8,16 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxAnswer = 999999
|
||||
maxIntAnswer = 999999
|
||||
)
|
||||
|
||||
type Answer string
|
||||
|
||||
func NewIntAnswer() Answer {
|
||||
ans, _ := rand.Int(rand.Reader, big.NewInt(maxIntAnswer))
|
||||
return (Answer(ans.String()))
|
||||
}
|
||||
|
||||
// Captcha interface that should be implemented by captcha.
|
||||
type Captcha interface {
|
||||
// Image generates and returns an image of captcha.
|
||||
@ -54,7 +59,7 @@ func (c *BaseCaptcha) Solve(answer Answer) bool {
|
||||
|
||||
func (c *BaseCaptcha) GetAnswer() Answer {
|
||||
if c.Answer == "" {
|
||||
c.Answer = generateAnswer()
|
||||
c.Answer = NewIntAnswer()
|
||||
}
|
||||
return c.Answer
|
||||
}
|
||||
@ -67,11 +72,6 @@ func (c *BaseCaptcha) Expiry() time.Time {
|
||||
return c.ExpireIn
|
||||
}
|
||||
|
||||
func generateAnswer() Answer {
|
||||
ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer))
|
||||
return (Answer(ans.String()))
|
||||
}
|
||||
|
||||
func ExpiryDate(expiry time.Duration) time.Time {
|
||||
return time.Now().Add(expiry)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user