42 lines
746 B
Go
42 lines
746 B
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand/v2"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func GenerateID() string {
|
|
return uuid.New().String()
|
|
}
|
|
|
|
func GenerateOTP() string {
|
|
num := 100000 + rand.UintN(899999)
|
|
return fmt.Sprintf("%d", num) // 6 digit random number [100,000 - 999,999]
|
|
}
|
|
|
|
func GenerateFastCode() string {
|
|
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
var code string
|
|
for i := 0; i < 6; i++ {
|
|
code += string(letters[rand.UintN(uint(len(letters)))])
|
|
}
|
|
return code
|
|
}
|
|
|
|
func MaskPhone(phone string) string {
|
|
if phone == "" {
|
|
return ""
|
|
}
|
|
return phone[:4] + "**" + phone[len(phone)-2:]
|
|
}
|
|
|
|
func MaskEmail(email string) string {
|
|
if email == "" {
|
|
return ""
|
|
}
|
|
return email[:3] + "**" + email[strings.Index(email, "@"):]
|
|
}
|