-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exmaple usages of generator and validator
- Loading branch information
1 parent
a9f635a
commit 117b383
Showing
2 changed files
with
80 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
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,28 @@ | ||
package token | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
"time" | ||
|
||
"github.com/Mobilpadde/moths/v5/token/emojies" | ||
) | ||
|
||
func ExampleGenerator_Validate() { | ||
amount := 6 | ||
secret := strings.Repeat("a", 32) | ||
|
||
var err error | ||
var gen *Generator | ||
if gen, err = NewGenerator( | ||
OptionWithSecret(secret), | ||
OptionWithPeriod(time.Second), | ||
OptionWithAmount(amount), | ||
OptionWithEmojies(emojies.CATS), | ||
); err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
code, _ := gen.Next() | ||
gen.Validate(code.String()) // This is true, as it's validated within specified period. | ||
} |