generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package captcha | ||
|
||
import ( | ||
"math/rand" | ||
) | ||
|
||
func NewRandomCaptcha() Captcha { | ||
availables := []func() Captcha{ | ||
NewBannerCaptcha, | ||
NewMathCaptcha, | ||
} | ||
return availables[rand.Intn(len(availables))]() // nolint:gosec | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package captcha_test | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
|
||
"moul.io/captcha/captcha" | ||
) | ||
|
||
func ExampleNewRandomCaptcha() { | ||
rand.Seed(42) | ||
|
||
// first captcha | ||
c := captcha.NewRandomCaptcha() | ||
question, _ := c.Question() | ||
fmt.Println(question) | ||
|
||
// second captcha | ||
c = captcha.NewRandomCaptcha() | ||
question, _ = c.Question() | ||
fmt.Println(question) | ||
|
||
// Output: | ||
// 3 + 4 | ||
// _ _ | ||
// _ __ | |_ | |_ _ _ ___ | ||
// | '_ \| _|| _|| || |/ -_) | ||
// | .__/ \__| \__| \_,_|\___| | ||
// |_| | ||
} |