-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
41 lines (32 loc) · 834 Bytes
/
utils.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
package gobble
import "strings"
func isValidCollectionName(name string) bool {
if len(name) == 0 {
return false
}
validChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_"
for _, c := range name {
if !strings.ContainsRune(validChars, c) {
return false
}
}
if strings.ContainsRune("-_", rune(name[0])) || strings.ContainsRune(".-_", rune(name[len(name)-1])) {
return false
}
return true
}
func isValidIndexName(name string) bool {
if len(name) == 0 {
return false
}
validChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_"
for _, c := range name {
if !strings.ContainsRune(validChars, c) {
return false
}
}
if strings.ContainsRune("-_", rune(name[0])) || strings.ContainsRune(".-_", rune(name[len(name)-1])) {
return false
}
return true
}