-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.go
More file actions
36 lines (29 loc) · 765 Bytes
/
validator.go
File metadata and controls
36 lines (29 loc) · 765 Bytes
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
package veil
// validate validates the rule set.
func validate(rules []Rule) error {
// check for duplicates
err := checkDuplicateRules(rules)
if err != nil {
return err
}
return nil
}
// checkDuplicateRules checks to see whether the same regexp pattern is used in more than one rules.
func checkDuplicateRules(rules []Rule) error {
for _, rule := range rules {
if isPatternDuplicated(rules, rule.pattern) {
return errDuplicateRule(rule.pattern)
}
}
return nil
}
// isPatternDuplicated checks whether there are more than one occurrence of the pattern in the rule set.
func isPatternDuplicated(rules []Rule, pattern string) bool {
count := 0
for _, rule := range rules {
if pattern == rule.pattern {
count++
}
}
return count > 1
}