Move rand string func to util for reuse

This commit is contained in:
Tim Hockin
2015-06-02 18:43:40 -07:00
parent 3afda5d566
commit 7874743a43
3 changed files with 88 additions and 13 deletions

View File

@@ -18,7 +18,8 @@ package api
import (
"fmt"
"math/rand"
utilrand "github.com/GoogleCloudPlatform/kubernetes/pkg/util/rand"
)
// NameGenerator generates names for objects. Some backends may have more information
@@ -59,16 +60,5 @@ func (simpleNameGenerator) GenerateName(base string) string {
if len(base) > maxGeneratedNameLength {
base = base[:maxGeneratedNameLength]
}
value := randSeq(randomLength)
return fmt.Sprintf("%s%s", base, value)
}
var letters = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
return fmt.Sprintf("%s%s", base, utilrand.String(randomLength))
}