added generate code

main v1.0.17
alex 2023-10-20 15:42:56 +02:00
parent 104bf06b8b
commit 0d49eba93f
1 changed files with 19 additions and 0 deletions

View File

@ -46,6 +46,25 @@ func GenerateSession() (string, error) {
return string(r), nil
}
func GenerateCode(codeLength int) (string, error) {
var letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
r := make([]byte, codeLength)
for i := 0; i < codeLength; i++ {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
if err != nil {
log.Error().Msgf("Failed to session: %v", err)
return "", err
}
r[i] = letters[num.Int64()]
}
return string(r), nil
}
func ParamsParserHelper(c *fiber.Ctx, params interface{}) error {
if err := c.ParamsParser(params); err != nil {
log.Error().Msgf("Failed to parse params, err: %s", err.Error())