1
0
mirror of https://github.com/rancher/norman.git synced 2025-06-29 16:58:05 +00:00
norman/types/id.go

20 lines
358 B
Go
Raw Normal View History

2018-04-15 06:37:22 +00:00
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("1%s-%s", strings.ToLower(base), last)
}