-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule_parser.go
51 lines (42 loc) · 868 Bytes
/
rule_parser.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 laravalidate
import (
"fmt"
"strings"
)
type validationRule struct {
validator registeredValidatorT
name string
args []string
}
func validationRules(input string) []validationRule {
rules := []validationRule{}
if len(input) == 0 {
return rules
}
sections := strings.Split(input, "|")
for _, section := range sections {
if len(section) == 0 {
continue
}
nameAndArgs := strings.SplitN(section, ":", 2)
name := nameAndArgs[0]
if name == "" {
continue
}
validator, ok := validators[name]
if !ok {
fmt.Printf(`Laravalidate: Unknown validation rule "%s"`+"\n", name)
continue
}
args := []string{}
if len(nameAndArgs) > 1 {
args = strings.Split(nameAndArgs[1], ",")
}
rules = append(rules, validationRule{
validator: validator,
name: name,
args: args,
})
}
return rules
}