1// Code generated by protoc-gen-validate. DO NOT EDIT. 2// source: envoy/type/matcher/v4alpha/string.proto 3 4package envoy_type_matcher_v4alpha 5 6import ( 7 "bytes" 8 "errors" 9 "fmt" 10 "net" 11 "net/mail" 12 "net/url" 13 "regexp" 14 "strings" 15 "time" 16 "unicode/utf8" 17 18 "github.com/golang/protobuf/ptypes" 19) 20 21// ensure the imports are used 22var ( 23 _ = bytes.MinRead 24 _ = errors.New("") 25 _ = fmt.Print 26 _ = utf8.UTFMax 27 _ = (*regexp.Regexp)(nil) 28 _ = (*strings.Reader)(nil) 29 _ = net.IPv4len 30 _ = time.Duration(0) 31 _ = (*url.URL)(nil) 32 _ = (*mail.Address)(nil) 33 _ = ptypes.DynamicAny{} 34) 35 36// Validate checks the field values on StringMatcher with the rules defined in 37// the proto definition for this message. If any rules are violated, an error 38// is returned. 39func (m *StringMatcher) Validate() error { 40 if m == nil { 41 return nil 42 } 43 44 // no validation rules for IgnoreCase 45 46 switch m.MatchPattern.(type) { 47 48 case *StringMatcher_Exact: 49 // no validation rules for Exact 50 51 case *StringMatcher_Prefix: 52 53 if utf8.RuneCountInString(m.GetPrefix()) < 1 { 54 return StringMatcherValidationError{ 55 field: "Prefix", 56 reason: "value length must be at least 1 runes", 57 } 58 } 59 60 case *StringMatcher_Suffix: 61 62 if utf8.RuneCountInString(m.GetSuffix()) < 1 { 63 return StringMatcherValidationError{ 64 field: "Suffix", 65 reason: "value length must be at least 1 runes", 66 } 67 } 68 69 case *StringMatcher_SafeRegex: 70 71 if m.GetSafeRegex() == nil { 72 return StringMatcherValidationError{ 73 field: "SafeRegex", 74 reason: "value is required", 75 } 76 } 77 78 if v, ok := interface{}(m.GetSafeRegex()).(interface{ Validate() error }); ok { 79 if err := v.Validate(); err != nil { 80 return StringMatcherValidationError{ 81 field: "SafeRegex", 82 reason: "embedded message failed validation", 83 cause: err, 84 } 85 } 86 } 87 88 case *StringMatcher_Contains: 89 90 if utf8.RuneCountInString(m.GetContains()) < 1 { 91 return StringMatcherValidationError{ 92 field: "Contains", 93 reason: "value length must be at least 1 runes", 94 } 95 } 96 97 default: 98 return StringMatcherValidationError{ 99 field: "MatchPattern", 100 reason: "value is required", 101 } 102 103 } 104 105 return nil 106} 107 108// StringMatcherValidationError is the validation error returned by 109// StringMatcher.Validate if the designated constraints aren't met. 110type StringMatcherValidationError struct { 111 field string 112 reason string 113 cause error 114 key bool 115} 116 117// Field function returns field value. 118func (e StringMatcherValidationError) Field() string { return e.field } 119 120// Reason function returns reason value. 121func (e StringMatcherValidationError) Reason() string { return e.reason } 122 123// Cause function returns cause value. 124func (e StringMatcherValidationError) Cause() error { return e.cause } 125 126// Key function returns key value. 127func (e StringMatcherValidationError) Key() bool { return e.key } 128 129// ErrorName returns error name. 130func (e StringMatcherValidationError) ErrorName() string { return "StringMatcherValidationError" } 131 132// Error satisfies the builtin error interface 133func (e StringMatcherValidationError) Error() string { 134 cause := "" 135 if e.cause != nil { 136 cause = fmt.Sprintf(" | caused by: %v", e.cause) 137 } 138 139 key := "" 140 if e.key { 141 key = "key for " 142 } 143 144 return fmt.Sprintf( 145 "invalid %sStringMatcher.%s: %s%s", 146 key, 147 e.field, 148 e.reason, 149 cause) 150} 151 152var _ error = StringMatcherValidationError{} 153 154var _ interface { 155 Field() string 156 Reason() string 157 Key() bool 158 Cause() error 159 ErrorName() string 160} = StringMatcherValidationError{} 161 162// Validate checks the field values on ListStringMatcher with the rules defined 163// in the proto definition for this message. If any rules are violated, an 164// error is returned. 165func (m *ListStringMatcher) Validate() error { 166 if m == nil { 167 return nil 168 } 169 170 if len(m.GetPatterns()) < 1 { 171 return ListStringMatcherValidationError{ 172 field: "Patterns", 173 reason: "value must contain at least 1 item(s)", 174 } 175 } 176 177 for idx, item := range m.GetPatterns() { 178 _, _ = idx, item 179 180 if v, ok := interface{}(item).(interface{ Validate() error }); ok { 181 if err := v.Validate(); err != nil { 182 return ListStringMatcherValidationError{ 183 field: fmt.Sprintf("Patterns[%v]", idx), 184 reason: "embedded message failed validation", 185 cause: err, 186 } 187 } 188 } 189 190 } 191 192 return nil 193} 194 195// ListStringMatcherValidationError is the validation error returned by 196// ListStringMatcher.Validate if the designated constraints aren't met. 197type ListStringMatcherValidationError struct { 198 field string 199 reason string 200 cause error 201 key bool 202} 203 204// Field function returns field value. 205func (e ListStringMatcherValidationError) Field() string { return e.field } 206 207// Reason function returns reason value. 208func (e ListStringMatcherValidationError) Reason() string { return e.reason } 209 210// Cause function returns cause value. 211func (e ListStringMatcherValidationError) Cause() error { return e.cause } 212 213// Key function returns key value. 214func (e ListStringMatcherValidationError) Key() bool { return e.key } 215 216// ErrorName returns error name. 217func (e ListStringMatcherValidationError) ErrorName() string { 218 return "ListStringMatcherValidationError" 219} 220 221// Error satisfies the builtin error interface 222func (e ListStringMatcherValidationError) Error() string { 223 cause := "" 224 if e.cause != nil { 225 cause = fmt.Sprintf(" | caused by: %v", e.cause) 226 } 227 228 key := "" 229 if e.key { 230 key = "key for " 231 } 232 233 return fmt.Sprintf( 234 "invalid %sListStringMatcher.%s: %s%s", 235 key, 236 e.field, 237 e.reason, 238 cause) 239} 240 241var _ error = ListStringMatcherValidationError{} 242 243var _ interface { 244 Field() string 245 Reason() string 246 Key() bool 247 Cause() error 248 ErrorName() string 249} = ListStringMatcherValidationError{} 250