parent
104bf06b8b
commit
0d49eba93f
|
@ -46,6 +46,25 @@ func GenerateSession() (string, error) {
|
||||||
return string(r), nil
|
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 {
|
func ParamsParserHelper(c *fiber.Ctx, params interface{}) error {
|
||||||
if err := c.ParamsParser(params); err != nil {
|
if err := c.ParamsParser(params); err != nil {
|
||||||
log.Error().Msgf("Failed to parse params, err: %s", err.Error())
|
log.Error().Msgf("Failed to parse params, err: %s", err.Error())
|
||||||
|
|
Loading…
Reference in New Issue