github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/type/matcher/string.pb.validate.go (about) 1 // Code generated by protoc-gen-validate. DO NOT EDIT. 2 // source: envoy/type/matcher/string.proto 3 4 package envoy_type_matcher 5 6 import ( 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 "google.golang.org/protobuf/types/known/anypb" 19 ) 20 21 // ensure the imports are used 22 var ( 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 _ = anypb.Any{} 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. 39 func (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_Regex: 70 71 if len(m.GetRegex()) > 1024 { 72 return StringMatcherValidationError{ 73 field: "Regex", 74 reason: "value length must be at most 1024 bytes", 75 } 76 } 77 78 case *StringMatcher_SafeRegex: 79 80 if m.GetSafeRegex() == nil { 81 return StringMatcherValidationError{ 82 field: "SafeRegex", 83 reason: "value is required", 84 } 85 } 86 87 if v, ok := interface{}(m.GetSafeRegex()).(interface{ Validate() error }); ok { 88 if err := v.Validate(); err != nil { 89 return StringMatcherValidationError{ 90 field: "SafeRegex", 91 reason: "embedded message failed validation", 92 cause: err, 93 } 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. 110 type StringMatcherValidationError struct { 111 field string 112 reason string 113 cause error 114 key bool 115 } 116 117 // Field function returns field value. 118 func (e StringMatcherValidationError) Field() string { return e.field } 119 120 // Reason function returns reason value. 121 func (e StringMatcherValidationError) Reason() string { return e.reason } 122 123 // Cause function returns cause value. 124 func (e StringMatcherValidationError) Cause() error { return e.cause } 125 126 // Key function returns key value. 127 func (e StringMatcherValidationError) Key() bool { return e.key } 128 129 // ErrorName returns error name. 130 func (e StringMatcherValidationError) ErrorName() string { return "StringMatcherValidationError" } 131 132 // Error satisfies the builtin error interface 133 func (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 152 var _ error = StringMatcherValidationError{} 153 154 var _ 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. 165 func (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. 197 type ListStringMatcherValidationError struct { 198 field string 199 reason string 200 cause error 201 key bool 202 } 203 204 // Field function returns field value. 205 func (e ListStringMatcherValidationError) Field() string { return e.field } 206 207 // Reason function returns reason value. 208 func (e ListStringMatcherValidationError) Reason() string { return e.reason } 209 210 // Cause function returns cause value. 211 func (e ListStringMatcherValidationError) Cause() error { return e.cause } 212 213 // Key function returns key value. 214 func (e ListStringMatcherValidationError) Key() bool { return e.key } 215 216 // ErrorName returns error name. 217 func (e ListStringMatcherValidationError) ErrorName() string { 218 return "ListStringMatcherValidationError" 219 } 220 221 // Error satisfies the builtin error interface 222 func (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 241 var _ error = ListStringMatcherValidationError{} 242 243 var _ interface { 244 Field() string 245 Reason() string 246 Key() bool 247 Cause() error 248 ErrorName() string 249 } = ListStringMatcherValidationError{}