-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
database.go
40 lines (31 loc) · 1012 Bytes
/
database.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
package validate
import (
"fmt"
"regexp"
)
func MariaDatabaseCollation(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
return
}
matched, _ := regexp.MatchString(`^[A-Za-z0-9_. ]+$`, v)
if !matched {
errors = append(errors, fmt.Errorf("%s contains invalid characters, only alphanumeric, underscore, space characters are supported, got %s", k, v))
return
}
return warnings, errors
}
func PostgresDatabaseCollation(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
return
}
matched, _ := regexp.MatchString(`^[-A-Za-z0-9_. ]+$`, v)
if !matched {
errors = append(errors, fmt.Errorf("%s contains invalid characters, only alphanumeric, underscore, space or hyphen characters are supported, got %s", k, v))
return
}
return warnings, errors
}