1
0
mirror of https://github.com/rancher/norman.git synced 2025-06-28 16:27:25 +00:00
norman/types/id.go
2018-04-16 22:15:57 -07:00

20 lines
357 B
Go

package types
import (
"fmt"
"regexp"
"strings"
utilrand "k8s.io/apimachinery/pkg/util/rand"
)
var (
lowerChars = regexp.MustCompile("[a-z]+")
)
func GenerateName(typeName string) string {
base := typeName[0:1] + lowerChars.ReplaceAllString(typeName[1:], "")
last := utilrand.String(5)
return fmt.Sprintf("%s-%s", strings.ToLower(base), last)
}