-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrings.go
51 lines (44 loc) · 1.33 KB
/
strings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package testament
import (
"fmt"
"math/rand"
"strings"
)
// RandomString returns a randomly generates string with the length of count.
func RandomString(count int) string {
const runes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, count)
for i := range b {
b[i] = runes[rand.Intn(len(runes))]
}
return string(b)
}
// RandomLowerString returns a randomly generates lower-cased string with the
// length of count.
func RandomLowerString(count int) string {
return strings.ToLower(RandomString(count))
}
// StringSlice return a string slice with the provided length.
func StringSlice(n int) []string {
ret := make([]string, n)
for i := range ret {
ret[i] = RandomString(20)
}
return ret
}
// RandomStringSlice return a random string slice with maximum length of to.
func RandomStringSlice(to int) []string {
ret := make([]string, rand.Intn(to))
for i := range ret {
ret[i] = RandomString(20)
}
return ret
}
// RandomEmailAddress returns a random email address.
func RandomEmailAddress() string {
return fmt.Sprintf("%s@%s.%s", RandomLowerString(10), RandomLowerString(10), RandomLowerString(3))
}
// RandomS3Filename returns a random S3 filename with a subfolder.
func RandomS3Filename() string {
return fmt.Sprintf("s3://%s/%s.%s", RandomLowerString(10), RandomLowerString(10), RandomLowerString(3))
}