22 lines
465 B
Go
22 lines
465 B
Go
package helper
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
)
|
|
|
|
const IDCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
const IDLength = 11
|
|
|
|
func UUIDGenerator() string {
|
|
ID := make([]byte, IDLength)
|
|
for i := 0; i < IDLength; i++ {
|
|
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(IDCharset))))
|
|
if err != nil {
|
|
panic(err) // Handle error appropriately in production code
|
|
}
|
|
ID[i] = IDCharset[num.Int64()]
|
|
}
|
|
return string(ID)
|
|
}
|