Debian Codegraph @

go/xds/type/matcher/v3/ip.pb.validate.go

raw symbols SCIP
1 // Code generated by protoc-gen-validate. DO NOT EDIT.
2 // source: xds/type/matcher/v3/ip.proto
3
4 package v3
5
6 import (
7 "bytes"
8 "errors"
9 "fmt"
10 "net"
11 "net/mail"
12 "net/url"
13 "regexp"
14 "sort"
15 "strings"
16 "time"
17 "unicode/utf8"
18
19 "google.golang.org/protobuf/types/known/anypb"
20 )
21
22 // ensure the imports are used
23 var (
24 _ = bytes.MinRead
25 _ = errors.New("")
26 _ = fmt.Print
27 _ = utf8.UTFMax
28 _ = (*regexp.Regexp)(nil)
29 _ = (*strings.Reader)(nil)
30 _ = net.IPv4len
31 _ = time.Duration(0)
32 _ = (*url.URL)(nil)
33 _ = (*mail.Address)(nil)
34 _ = anypb.Any{}
35 _ = sort.Sort
36 )
37
38 // Validate checks the field values on IPMatcher with the rules defined in the
39 // proto definition for this message. If any rules are violated, the first
40 // error encountered is returned, or nil if there are no violations.
41 func (m *IPMatcher) Validate() error {
42 return m.validate(false)
43 }
44
45 // ValidateAll checks the field values on IPMatcher with the rules defined in
46 // the proto definition for this message. If any rules are violated, the
47 // result is a list of violation errors wrapped in IPMatcherMultiError, or nil
48 // if none found.
49 func (m *IPMatcher) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *IPMatcher) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 for idx, item := range m.GetRangeMatchers() {
61 _, _ = idx, item
62
63 if all {
64 switch v := interface{}(item).(type) {
65 case interface{ ValidateAll() error }:
66 if err := v.ValidateAll(); err != nil {
67 errors = append(errors, IPMatcherValidationError{
68 field: fmt.Sprintf("RangeMatchers[%v]", idx),
69 reason: "embedded message failed validation",
70 cause: err,
71 })
72 }
73 case interface{ Validate() error }:
74 if err := v.Validate(); err != nil {
75 errors = append(errors, IPMatcherValidationError{
76 field: fmt.Sprintf("RangeMatchers[%v]", idx),
77 reason: "embedded message failed validation",
78 cause: err,
79 })
80 }
81 }
82 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
83 if err := v.Validate(); err != nil {
84 return IPMatcherValidationError{
85 field: fmt.Sprintf("RangeMatchers[%v]", idx),
86 reason: "embedded message failed validation",
87 cause: err,
88 }
89 }
90 }
91
92 }
93
94 if len(errors) > 0 {
95 return IPMatcherMultiError(errors)
96 }
97
98 return nil
99 }
100
101 // IPMatcherMultiError is an error wrapping multiple validation errors returned
102 // by IPMatcher.ValidateAll() if the designated constraints aren't met.
103 type IPMatcherMultiError []error
104
105 // Error returns a concatenation of all the error messages it wraps.
106 func (m IPMatcherMultiError) Error() string {
107 msgs := make([]string, 0, len(m))
108 for _, err := range m {
109 msgs = append(msgs, err.Error())
110 }
111 return strings.Join(msgs, "; ")
112 }
113
114 // AllErrors returns a list of validation violation errors.
115 func (m IPMatcherMultiError) AllErrors() []error { return m }
116
117 // IPMatcherValidationError is the validation error returned by
118 // IPMatcher.Validate if the designated constraints aren't met.
119 type IPMatcherValidationError struct {
120 field string
121 reason string
122 cause error
123 key bool
124 }
125
126 // Field function returns field value.
127 func (e IPMatcherValidationError) Field() string { return e.field }
128
129 // Reason function returns reason value.
130 func (e IPMatcherValidationError) Reason() string { return e.reason }
131
132 // Cause function returns cause value.
133 func (e IPMatcherValidationError) Cause() error { return e.cause }
134
135 // Key function returns key value.
136 func (e IPMatcherValidationError) Key() bool { return e.key }
137
138 // ErrorName returns error name.
139 func (e IPMatcherValidationError) ErrorName() string { return "IPMatcherValidationError" }
140
141 // Error satisfies the builtin error interface
142 func (e IPMatcherValidationError) Error() string {
143 cause := ""
144 if e.cause != nil {
145 cause = fmt.Sprintf(" | caused by: %v", e.cause)
146 }
147
148 key := ""
149 if e.key {
150 key = "key for "
151 }
152
153 return fmt.Sprintf(
154 "invalid %sIPMatcher.%s: %s%s",
155 key,
156 e.field,
157 e.reason,
158 cause)
159 }
160
161 var _ error = IPMatcherValidationError{}
162
163 var _ interface {
164 Field() string
165 Reason() string
166 Key() bool
167 Cause() error
168 ErrorName() string
169 } = IPMatcherValidationError{}
170
171 // Validate checks the field values on IPMatcher_IPRangeMatcher with the rules
172 // defined in the proto definition for this message. If any rules are
173 // violated, the first error encountered is returned, or nil if there are no violations.
174 func (m *IPMatcher_IPRangeMatcher) Validate() error {
175 return m.validate(false)
176 }
177
178 // ValidateAll checks the field values on IPMatcher_IPRangeMatcher with the
179 // rules defined in the proto definition for this message. If any rules are
180 // violated, the result is a list of violation errors wrapped in
181 // IPMatcher_IPRangeMatcherMultiError, or nil if none found.
182 func (m *IPMatcher_IPRangeMatcher) ValidateAll() error {
183 return m.validate(true)
184 }
185
186 func (m *IPMatcher_IPRangeMatcher) validate(all bool) error {
187 if m == nil {
188 return nil
189 }
190
191 var errors []error
192
193 if len(m.GetRanges()) < 1 {
194 err := IPMatcher_IPRangeMatcherValidationError{
195 field: "Ranges",
196 reason: "value must contain at least 1 item(s)",
197 }
198 if !all {
199 return err
200 }
201 errors = append(errors, err)
202 }
203
204 for idx, item := range m.GetRanges() {
205 _, _ = idx, item
206
207 if all {
208 switch v := interface{}(item).(type) {
209 case interface{ ValidateAll() error }:
210 if err := v.ValidateAll(); err != nil {
211 errors = append(errors, IPMatcher_IPRangeMatcherValidationError{
212 field: fmt.Sprintf("Ranges[%v]", idx),
213 reason: "embedded message failed validation",
214 cause: err,
215 })
216 }
217 case interface{ Validate() error }:
218 if err := v.Validate(); err != nil {
219 errors = append(errors, IPMatcher_IPRangeMatcherValidationError{
220 field: fmt.Sprintf("Ranges[%v]", idx),
221 reason: "embedded message failed validation",
222 cause: err,
223 })
224 }
225 }
226 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
227 if err := v.Validate(); err != nil {
228 return IPMatcher_IPRangeMatcherValidationError{
229 field: fmt.Sprintf("Ranges[%v]", idx),
230 reason: "embedded message failed validation",
231 cause: err,
232 }
233 }
234 }
235
236 }
237
238 if all {
239 switch v := interface{}(m.GetOnMatch()).(type) {
240 case interface{ ValidateAll() error }:
241 if err := v.ValidateAll(); err != nil {
242 errors = append(errors, IPMatcher_IPRangeMatcherValidationError{
243 field: "OnMatch",
244 reason: "embedded message failed validation",
245 cause: err,
246 })
247 }
248 case interface{ Validate() error }:
249 if err := v.Validate(); err != nil {
250 errors = append(errors, IPMatcher_IPRangeMatcherValidationError{
251 field: "OnMatch",
252 reason: "embedded message failed validation",
253 cause: err,
254 })
255 }
256 }
257 } else if v, ok := interface{}(m.GetOnMatch()).(interface{ Validate() error }); ok {
258 if err := v.Validate(); err != nil {
259 return IPMatcher_IPRangeMatcherValidationError{
260 field: "OnMatch",
261 reason: "embedded message failed validation",
262 cause: err,
263 }
264 }
265 }
266
267 // no validation rules for Exclusive
268
269 if len(errors) > 0 {
270 return IPMatcher_IPRangeMatcherMultiError(errors)
271 }
272
273 return nil
274 }
275
276 // IPMatcher_IPRangeMatcherMultiError is an error wrapping multiple validation
277 // errors returned by IPMatcher_IPRangeMatcher.ValidateAll() if the designated
278 // constraints aren't met.
279 type IPMatcher_IPRangeMatcherMultiError []error
280
281 // Error returns a concatenation of all the error messages it wraps.
282 func (m IPMatcher_IPRangeMatcherMultiError) Error() string {
283 msgs := make([]string, 0, len(m))
284 for _, err := range m {
285 msgs = append(msgs, err.Error())
286 }
287 return strings.Join(msgs, "; ")
288 }
289
290 // AllErrors returns a list of validation violation errors.
291 func (m IPMatcher_IPRangeMatcherMultiError) AllErrors() []error { return m }
292
293 // IPMatcher_IPRangeMatcherValidationError is the validation error returned by
294 // IPMatcher_IPRangeMatcher.Validate if the designated constraints aren't met.
295 type IPMatcher_IPRangeMatcherValidationError struct {
296 field string
297 reason string
298 cause error
299 key bool
300 }
301
302 // Field function returns field value.
303 func (e IPMatcher_IPRangeMatcherValidationError) Field() string { return e.field }
304
305 // Reason function returns reason value.
306 func (e IPMatcher_IPRangeMatcherValidationError) Reason() string { return e.reason }
307
308 // Cause function returns cause value.
309 func (e IPMatcher_IPRangeMatcherValidationError) Cause() error { return e.cause }
310
311 // Key function returns key value.
312 func (e IPMatcher_IPRangeMatcherValidationError) Key() bool { return e.key }
313
314 // ErrorName returns error name.
315 func (e IPMatcher_IPRangeMatcherValidationError) ErrorName() string {
316 return "IPMatcher_IPRangeMatcherValidationError"
317 }
318
319 // Error satisfies the builtin error interface
320 func (e IPMatcher_IPRangeMatcherValidationError) Error() string {
321 cause := ""
322 if e.cause != nil {
323 cause = fmt.Sprintf(" | caused by: %v", e.cause)
324 }
325
326 key := ""
327 if e.key {
328 key = "key for "
329 }
330
331 return fmt.Sprintf(
332 "invalid %sIPMatcher_IPRangeMatcher.%s: %s%s",
333 key,
334 e.field,
335 e.reason,
336 cause)
337 }
338
339 var _ error = IPMatcher_IPRangeMatcherValidationError{}
340
341 var _ interface {
342 Field() string
343 Reason() string
344 Key() bool
345 Cause() error
346 ErrorName() string
347 } = IPMatcher_IPRangeMatcherValidationError{}