Debian Codegraph @

go/xds/core/v3/resource_locator.pb.validate.go

raw symbols SCIP
1 // Code generated by protoc-gen-validate. DO NOT EDIT.
2 // source: xds/core/v3/resource_locator.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 ResourceLocator with the rules defined
39 // in the proto definition for this message. If any rules are violated, the
40 // first error encountered is returned, or nil if there are no violations.
41 func (m *ResourceLocator) Validate() error {
42 return m.validate(false)
43 }
44
45 // ValidateAll checks the field values on ResourceLocator with the rules
46 // defined in the proto definition for this message. If any rules are
47 // violated, the result is a list of violation errors wrapped in
48 // ResourceLocatorMultiError, or nil if none found.
49 func (m *ResourceLocator) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *ResourceLocator) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if _, ok := ResourceLocator_Scheme_name[int32(m.GetScheme())]; !ok {
61 err := ResourceLocatorValidationError{
62 field: "Scheme",
63 reason: "value must be one of the defined enum values",
64 }
65 if !all {
66 return err
67 }
68 errors = append(errors, err)
69 }
70
71 // no validation rules for Id
72
73 // no validation rules for Authority
74
75 if utf8.RuneCountInString(m.GetResourceType()) < 1 {
76 err := ResourceLocatorValidationError{
77 field: "ResourceType",
78 reason: "value length must be at least 1 runes",
79 }
80 if !all {
81 return err
82 }
83 errors = append(errors, err)
84 }
85
86 for idx, item := range m.GetDirectives() {
87 _, _ = idx, item
88
89 if all {
90 switch v := interface{}(item).(type) {
91 case interface{ ValidateAll() error }:
92 if err := v.ValidateAll(); err != nil {
93 errors = append(errors, ResourceLocatorValidationError{
94 field: fmt.Sprintf("Directives[%v]", idx),
95 reason: "embedded message failed validation",
96 cause: err,
97 })
98 }
99 case interface{ Validate() error }:
100 if err := v.Validate(); err != nil {
101 errors = append(errors, ResourceLocatorValidationError{
102 field: fmt.Sprintf("Directives[%v]", idx),
103 reason: "embedded message failed validation",
104 cause: err,
105 })
106 }
107 }
108 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
109 if err := v.Validate(); err != nil {
110 return ResourceLocatorValidationError{
111 field: fmt.Sprintf("Directives[%v]", idx),
112 reason: "embedded message failed validation",
113 cause: err,
114 }
115 }
116 }
117
118 }
119
120 switch v := m.ContextParamSpecifier.(type) {
121 case *ResourceLocator_ExactContext:
122 if v == nil {
123 err := ResourceLocatorValidationError{
124 field: "ContextParamSpecifier",
125 reason: "oneof value cannot be a typed-nil",
126 }
127 if !all {
128 return err
129 }
130 errors = append(errors, err)
131 }
132
133 if all {
134 switch v := interface{}(m.GetExactContext()).(type) {
135 case interface{ ValidateAll() error }:
136 if err := v.ValidateAll(); err != nil {
137 errors = append(errors, ResourceLocatorValidationError{
138 field: "ExactContext",
139 reason: "embedded message failed validation",
140 cause: err,
141 })
142 }
143 case interface{ Validate() error }:
144 if err := v.Validate(); err != nil {
145 errors = append(errors, ResourceLocatorValidationError{
146 field: "ExactContext",
147 reason: "embedded message failed validation",
148 cause: err,
149 })
150 }
151 }
152 } else if v, ok := interface{}(m.GetExactContext()).(interface{ Validate() error }); ok {
153 if err := v.Validate(); err != nil {
154 return ResourceLocatorValidationError{
155 field: "ExactContext",
156 reason: "embedded message failed validation",
157 cause: err,
158 }
159 }
160 }
161
162 default:
163 _ = v // ensures v is used
164 }
165
166 if len(errors) > 0 {
167 return ResourceLocatorMultiError(errors)
168 }
169
170 return nil
171 }
172
173 // ResourceLocatorMultiError is an error wrapping multiple validation errors
174 // returned by ResourceLocator.ValidateAll() if the designated constraints
175 // aren't met.
176 type ResourceLocatorMultiError []error
177
178 // Error returns a concatenation of all the error messages it wraps.
179 func (m ResourceLocatorMultiError) Error() string {
180 msgs := make([]string, 0, len(m))
181 for _, err := range m {
182 msgs = append(msgs, err.Error())
183 }
184 return strings.Join(msgs, "; ")
185 }
186
187 // AllErrors returns a list of validation violation errors.
188 func (m ResourceLocatorMultiError) AllErrors() []error { return m }
189
190 // ResourceLocatorValidationError is the validation error returned by
191 // ResourceLocator.Validate if the designated constraints aren't met.
192 type ResourceLocatorValidationError struct {
193 field string
194 reason string
195 cause error
196 key bool
197 }
198
199 // Field function returns field value.
200 func (e ResourceLocatorValidationError) Field() string { return e.field }
201
202 // Reason function returns reason value.
203 func (e ResourceLocatorValidationError) Reason() string { return e.reason }
204
205 // Cause function returns cause value.
206 func (e ResourceLocatorValidationError) Cause() error { return e.cause }
207
208 // Key function returns key value.
209 func (e ResourceLocatorValidationError) Key() bool { return e.key }
210
211 // ErrorName returns error name.
212 func (e ResourceLocatorValidationError) ErrorName() string { return "ResourceLocatorValidationError" }
213
214 // Error satisfies the builtin error interface
215 func (e ResourceLocatorValidationError) Error() string {
216 cause := ""
217 if e.cause != nil {
218 cause = fmt.Sprintf(" | caused by: %v", e.cause)
219 }
220
221 key := ""
222 if e.key {
223 key = "key for "
224 }
225
226 return fmt.Sprintf(
227 "invalid %sResourceLocator.%s: %s%s",
228 key,
229 e.field,
230 e.reason,
231 cause)
232 }
233
234 var _ error = ResourceLocatorValidationError{}
235
236 var _ interface {
237 Field() string
238 Reason() string
239 Key() bool
240 Cause() error
241 ErrorName() string
242 } = ResourceLocatorValidationError{}
243
244 // Validate checks the field values on ResourceLocator_Directive with the rules
245 // defined in the proto definition for this message. If any rules are
246 // violated, the first error encountered is returned, or nil if there are no violations.
247 func (m *ResourceLocator_Directive) Validate() error {
248 return m.validate(false)
249 }
250
251 // ValidateAll checks the field values on ResourceLocator_Directive with the
252 // rules defined in the proto definition for this message. If any rules are
253 // violated, the result is a list of violation errors wrapped in
254 // ResourceLocator_DirectiveMultiError, or nil if none found.
255 func (m *ResourceLocator_Directive) ValidateAll() error {
256 return m.validate(true)
257 }
258
259 func (m *ResourceLocator_Directive) validate(all bool) error {
260 if m == nil {
261 return nil
262 }
263
264 var errors []error
265
266 oneofDirectivePresent := false
267 switch v := m.Directive.(type) {
268 case *ResourceLocator_Directive_Alt:
269 if v == nil {
270 err := ResourceLocator_DirectiveValidationError{
271 field: "Directive",
272 reason: "oneof value cannot be a typed-nil",
273 }
274 if !all {
275 return err
276 }
277 errors = append(errors, err)
278 }
279 oneofDirectivePresent = true
280
281 if all {
282 switch v := interface{}(m.GetAlt()).(type) {
283 case interface{ ValidateAll() error }:
284 if err := v.ValidateAll(); err != nil {
285 errors = append(errors, ResourceLocator_DirectiveValidationError{
286 field: "Alt",
287 reason: "embedded message failed validation",
288 cause: err,
289 })
290 }
291 case interface{ Validate() error }:
292 if err := v.Validate(); err != nil {
293 errors = append(errors, ResourceLocator_DirectiveValidationError{
294 field: "Alt",
295 reason: "embedded message failed validation",
296 cause: err,
297 })
298 }
299 }
300 } else if v, ok := interface{}(m.GetAlt()).(interface{ Validate() error }); ok {
301 if err := v.Validate(); err != nil {
302 return ResourceLocator_DirectiveValidationError{
303 field: "Alt",
304 reason: "embedded message failed validation",
305 cause: err,
306 }
307 }
308 }
309
310 case *ResourceLocator_Directive_Entry:
311 if v == nil {
312 err := ResourceLocator_DirectiveValidationError{
313 field: "Directive",
314 reason: "oneof value cannot be a typed-nil",
315 }
316 if !all {
317 return err
318 }
319 errors = append(errors, err)
320 }
321 oneofDirectivePresent = true
322
323 if utf8.RuneCountInString(m.GetEntry()) < 1 {
324 err := ResourceLocator_DirectiveValidationError{
325 field: "Entry",
326 reason: "value length must be at least 1 runes",
327 }
328 if !all {
329 return err
330 }
331 errors = append(errors, err)
332 }
333
334 if !_ResourceLocator_Directive_Entry_Pattern.MatchString(m.GetEntry()) {
335 err := ResourceLocator_DirectiveValidationError{
336 field: "Entry",
337 reason: "value does not match regex pattern \"^[0-9a-zA-Z_\\\\-\\\\./~:]+$\"",
338 }
339 if !all {
340 return err
341 }
342 errors = append(errors, err)
343 }
344
345 default:
346 _ = v // ensures v is used
347 }
348 if !oneofDirectivePresent {
349 err := ResourceLocator_DirectiveValidationError{
350 field: "Directive",
351 reason: "value is required",
352 }
353 if !all {
354 return err
355 }
356 errors = append(errors, err)
357 }
358
359 if len(errors) > 0 {
360 return ResourceLocator_DirectiveMultiError(errors)
361 }
362
363 return nil
364 }
365
366 // ResourceLocator_DirectiveMultiError is an error wrapping multiple validation
367 // errors returned by ResourceLocator_Directive.ValidateAll() if the
368 // designated constraints aren't met.
369 type ResourceLocator_DirectiveMultiError []error
370
371 // Error returns a concatenation of all the error messages it wraps.
372 func (m ResourceLocator_DirectiveMultiError) Error() string {
373 msgs := make([]string, 0, len(m))
374 for _, err := range m {
375 msgs = append(msgs, err.Error())
376 }
377 return strings.Join(msgs, "; ")
378 }
379
380 // AllErrors returns a list of validation violation errors.
381 func (m ResourceLocator_DirectiveMultiError) AllErrors() []error { return m }
382
383 // ResourceLocator_DirectiveValidationError is the validation error returned by
384 // ResourceLocator_Directive.Validate if the designated constraints aren't met.
385 type ResourceLocator_DirectiveValidationError struct {
386 field string
387 reason string
388 cause error
389 key bool
390 }
391
392 // Field function returns field value.
393 func (e ResourceLocator_DirectiveValidationError) Field() string { return e.field }
394
395 // Reason function returns reason value.
396 func (e ResourceLocator_DirectiveValidationError) Reason() string { return e.reason }
397
398 // Cause function returns cause value.
399 func (e ResourceLocator_DirectiveValidationError) Cause() error { return e.cause }
400
401 // Key function returns key value.
402 func (e ResourceLocator_DirectiveValidationError) Key() bool { return e.key }
403
404 // ErrorName returns error name.
405 func (e ResourceLocator_DirectiveValidationError) ErrorName() string {
406 return "ResourceLocator_DirectiveValidationError"
407 }
408
409 // Error satisfies the builtin error interface
410 func (e ResourceLocator_DirectiveValidationError) Error() string {
411 cause := ""
412 if e.cause != nil {
413 cause = fmt.Sprintf(" | caused by: %v", e.cause)
414 }
415
416 key := ""
417 if e.key {
418 key = "key for "
419 }
420
421 return fmt.Sprintf(
422 "invalid %sResourceLocator_Directive.%s: %s%s",
423 key,
424 e.field,
425 e.reason,
426 cause)
427 }
428
429 var _ error = ResourceLocator_DirectiveValidationError{}
430
431 var _ interface {
432 Field() string
433 Reason() string
434 Key() bool
435 Cause() error
436 ErrorName() string
437 } = ResourceLocator_DirectiveValidationError{}
438
439 var _ResourceLocator_Directive_Entry_Pattern = regexp.MustCompile("^[0-9a-zA-Z_\\-\\./~:]+$")