Add helper function to create a unique givenname

This commit is contained in:
Kristoffer Dalby 2022-05-16 20:30:43 +02:00
parent f4873d9387
commit 177c21b294
3 changed files with 177 additions and 0 deletions

View file

@ -317,3 +317,16 @@ func GenerateRandomStringURLSafe(n int) (string, error) {
return base64.RawURLEncoding.EncodeToString(b), err
}
// GenerateRandomStringDNSSafe returns a DNS-safe
// securely generated random string.
// It will return an error if the system's secure random
// number generator fails to function correctly, in which
// case the caller should not continue.
func GenerateRandomStringDNSSafe(n int) (string, error) {
str, err := GenerateRandomStringURLSafe(n)
str = strings.ReplaceAll(str, "_", "-")
return str[:n], err
}