mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-06 14:16:51 +08:00

- This is specific to us because of how we combine uid and namespace to create the subdomain.
17 lines
359 B
Go
17 lines
359 B
Go
package uid
|
|
|
|
import (
|
|
"errors"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
func GenerateUID(input string) (string, error) {
|
|
re, _ := regexp.Compile(`[^a-zA-Z0-9-]{1,}`)
|
|
cleanUp := strings.ToLower(re.ReplaceAllString(input, `-`))
|
|
if len(cleanUp) > 30 {
|
|
return "", errors.New("Length of string exceeds 30.")
|
|
}
|
|
return strings.ToLower(re.ReplaceAllString(input, `-`)), nil
|
|
}
|