8
// validator houses a set of rule needed for validation of a
12
// rule interface allows for more flexible rules and just simply
13
// checks whether or not a value adheres to that rule
15
IsValid(value string) bool
18
// IsValid will iterate through all rules and see if any rules
19
// apply to the value and supports nested rules
20
func (r rules) IsValid(value string) bool {
21
for _, rule := range r {
22
if rule.IsValid(value) {
29
// mapRule generic rule for maps
30
type mapRule map[string]struct{}
32
// IsValid for the map rule satisfies whether it exists in the map
33
func (m mapRule) IsValid(value string) bool {
38
// whitelist is a generic rule for whitelisting
39
type whitelist struct {
43
// IsValid for whitelist checks if the value is within the whitelist
44
func (w whitelist) IsValid(value string) bool {
45
return w.rule.IsValid(value)
48
// blacklist is a generic rule for blacklisting
49
type blacklist struct {
53
// IsValid for whitelist checks if the value is within the whitelist
54
func (b blacklist) IsValid(value string) bool {
55
return !b.rule.IsValid(value)
58
type patterns []string
60
// IsValid for patterns checks each pattern and returns if a match has
62
func (p patterns) IsValid(value string) bool {
63
for _, pattern := range p {
64
if strings.HasPrefix(http.CanonicalHeaderKey(value), pattern) {
71
// inclusiveRules rules allow for rules to depend on one another
72
type inclusiveRules []rule
74
// IsValid will return true if all rules are true
75
func (r inclusiveRules) IsValid(value string) bool {
76
for _, rule := range r {
77
if !rule.IsValid(value) {