1
2
3
4 package ratelimitv2
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
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
39
40
41 func (m *RateLimitRequest) Validate() error {
42 return m.validate(false)
43 }
44
45
46
47
48
49 func (m *RateLimitRequest) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *RateLimitRequest) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60
61
62 for idx, item := range m.GetDescriptors() {
63 _, _ = idx, item
64
65 if all {
66 switch v := interface{}(item).(type) {
67 case interface{ ValidateAll() error }:
68 if err := v.ValidateAll(); err != nil {
69 errors = append(errors, RateLimitRequestValidationError{
70 field: fmt.Sprintf("Descriptors[%v]", idx),
71 reason: "embedded message failed validation",
72 cause: err,
73 })
74 }
75 case interface{ Validate() error }:
76 if err := v.Validate(); err != nil {
77 errors = append(errors, RateLimitRequestValidationError{
78 field: fmt.Sprintf("Descriptors[%v]", idx),
79 reason: "embedded message failed validation",
80 cause: err,
81 })
82 }
83 }
84 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
85 if err := v.Validate(); err != nil {
86 return RateLimitRequestValidationError{
87 field: fmt.Sprintf("Descriptors[%v]", idx),
88 reason: "embedded message failed validation",
89 cause: err,
90 }
91 }
92 }
93
94 }
95
96
97
98 if len(errors) > 0 {
99 return RateLimitRequestMultiError(errors)
100 }
101
102 return nil
103 }
104
105
106
107
108 type RateLimitRequestMultiError []error
109
110
111 func (m RateLimitRequestMultiError) Error() string {
112 var msgs []string
113 for _, err := range m {
114 msgs = append(msgs, err.Error())
115 }
116 return strings.Join(msgs, "; ")
117 }
118
119
120 func (m RateLimitRequestMultiError) AllErrors() []error { return m }
121
122
123
124 type RateLimitRequestValidationError struct {
125 field string
126 reason string
127 cause error
128 key bool
129 }
130
131
132 func (e RateLimitRequestValidationError) Field() string { return e.field }
133
134
135 func (e RateLimitRequestValidationError) Reason() string { return e.reason }
136
137
138 func (e RateLimitRequestValidationError) Cause() error { return e.cause }
139
140
141 func (e RateLimitRequestValidationError) Key() bool { return e.key }
142
143
144 func (e RateLimitRequestValidationError) ErrorName() string { return "RateLimitRequestValidationError" }
145
146
147 func (e RateLimitRequestValidationError) Error() string {
148 cause := ""
149 if e.cause != nil {
150 cause = fmt.Sprintf(" | caused by: %v", e.cause)
151 }
152
153 key := ""
154 if e.key {
155 key = "key for "
156 }
157
158 return fmt.Sprintf(
159 "invalid %sRateLimitRequest.%s: %s%s",
160 key,
161 e.field,
162 e.reason,
163 cause)
164 }
165
166 var _ error = RateLimitRequestValidationError{}
167
168 var _ interface {
169 Field() string
170 Reason() string
171 Key() bool
172 Cause() error
173 ErrorName() string
174 } = RateLimitRequestValidationError{}
175
176
177
178
179 func (m *RateLimitResponse) Validate() error {
180 return m.validate(false)
181 }
182
183
184
185
186
187 func (m *RateLimitResponse) ValidateAll() error {
188 return m.validate(true)
189 }
190
191 func (m *RateLimitResponse) validate(all bool) error {
192 if m == nil {
193 return nil
194 }
195
196 var errors []error
197
198
199
200 for idx, item := range m.GetStatuses() {
201 _, _ = idx, item
202
203 if all {
204 switch v := interface{}(item).(type) {
205 case interface{ ValidateAll() error }:
206 if err := v.ValidateAll(); err != nil {
207 errors = append(errors, RateLimitResponseValidationError{
208 field: fmt.Sprintf("Statuses[%v]", idx),
209 reason: "embedded message failed validation",
210 cause: err,
211 })
212 }
213 case interface{ Validate() error }:
214 if err := v.Validate(); err != nil {
215 errors = append(errors, RateLimitResponseValidationError{
216 field: fmt.Sprintf("Statuses[%v]", idx),
217 reason: "embedded message failed validation",
218 cause: err,
219 })
220 }
221 }
222 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
223 if err := v.Validate(); err != nil {
224 return RateLimitResponseValidationError{
225 field: fmt.Sprintf("Statuses[%v]", idx),
226 reason: "embedded message failed validation",
227 cause: err,
228 }
229 }
230 }
231
232 }
233
234 for idx, item := range m.GetHeaders() {
235 _, _ = idx, item
236
237 if all {
238 switch v := interface{}(item).(type) {
239 case interface{ ValidateAll() error }:
240 if err := v.ValidateAll(); err != nil {
241 errors = append(errors, RateLimitResponseValidationError{
242 field: fmt.Sprintf("Headers[%v]", idx),
243 reason: "embedded message failed validation",
244 cause: err,
245 })
246 }
247 case interface{ Validate() error }:
248 if err := v.Validate(); err != nil {
249 errors = append(errors, RateLimitResponseValidationError{
250 field: fmt.Sprintf("Headers[%v]", idx),
251 reason: "embedded message failed validation",
252 cause: err,
253 })
254 }
255 }
256 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
257 if err := v.Validate(); err != nil {
258 return RateLimitResponseValidationError{
259 field: fmt.Sprintf("Headers[%v]", idx),
260 reason: "embedded message failed validation",
261 cause: err,
262 }
263 }
264 }
265
266 }
267
268 for idx, item := range m.GetRequestHeadersToAdd() {
269 _, _ = idx, item
270
271 if all {
272 switch v := interface{}(item).(type) {
273 case interface{ ValidateAll() error }:
274 if err := v.ValidateAll(); err != nil {
275 errors = append(errors, RateLimitResponseValidationError{
276 field: fmt.Sprintf("RequestHeadersToAdd[%v]", idx),
277 reason: "embedded message failed validation",
278 cause: err,
279 })
280 }
281 case interface{ Validate() error }:
282 if err := v.Validate(); err != nil {
283 errors = append(errors, RateLimitResponseValidationError{
284 field: fmt.Sprintf("RequestHeadersToAdd[%v]", idx),
285 reason: "embedded message failed validation",
286 cause: err,
287 })
288 }
289 }
290 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
291 if err := v.Validate(); err != nil {
292 return RateLimitResponseValidationError{
293 field: fmt.Sprintf("RequestHeadersToAdd[%v]", idx),
294 reason: "embedded message failed validation",
295 cause: err,
296 }
297 }
298 }
299
300 }
301
302 if len(errors) > 0 {
303 return RateLimitResponseMultiError(errors)
304 }
305
306 return nil
307 }
308
309
310
311
312 type RateLimitResponseMultiError []error
313
314
315 func (m RateLimitResponseMultiError) Error() string {
316 var msgs []string
317 for _, err := range m {
318 msgs = append(msgs, err.Error())
319 }
320 return strings.Join(msgs, "; ")
321 }
322
323
324 func (m RateLimitResponseMultiError) AllErrors() []error { return m }
325
326
327
328 type RateLimitResponseValidationError struct {
329 field string
330 reason string
331 cause error
332 key bool
333 }
334
335
336 func (e RateLimitResponseValidationError) Field() string { return e.field }
337
338
339 func (e RateLimitResponseValidationError) Reason() string { return e.reason }
340
341
342 func (e RateLimitResponseValidationError) Cause() error { return e.cause }
343
344
345 func (e RateLimitResponseValidationError) Key() bool { return e.key }
346
347
348 func (e RateLimitResponseValidationError) ErrorName() string {
349 return "RateLimitResponseValidationError"
350 }
351
352
353 func (e RateLimitResponseValidationError) Error() string {
354 cause := ""
355 if e.cause != nil {
356 cause = fmt.Sprintf(" | caused by: %v", e.cause)
357 }
358
359 key := ""
360 if e.key {
361 key = "key for "
362 }
363
364 return fmt.Sprintf(
365 "invalid %sRateLimitResponse.%s: %s%s",
366 key,
367 e.field,
368 e.reason,
369 cause)
370 }
371
372 var _ error = RateLimitResponseValidationError{}
373
374 var _ interface {
375 Field() string
376 Reason() string
377 Key() bool
378 Cause() error
379 ErrorName() string
380 } = RateLimitResponseValidationError{}
381
382
383
384
385 func (m *RateLimitResponse_RateLimit) Validate() error {
386 return m.validate(false)
387 }
388
389
390
391
392
393 func (m *RateLimitResponse_RateLimit) ValidateAll() error {
394 return m.validate(true)
395 }
396
397 func (m *RateLimitResponse_RateLimit) validate(all bool) error {
398 if m == nil {
399 return nil
400 }
401
402 var errors []error
403
404
405
406
407
408
409
410 if len(errors) > 0 {
411 return RateLimitResponse_RateLimitMultiError(errors)
412 }
413
414 return nil
415 }
416
417
418
419
420 type RateLimitResponse_RateLimitMultiError []error
421
422
423 func (m RateLimitResponse_RateLimitMultiError) Error() string {
424 var msgs []string
425 for _, err := range m {
426 msgs = append(msgs, err.Error())
427 }
428 return strings.Join(msgs, "; ")
429 }
430
431
432 func (m RateLimitResponse_RateLimitMultiError) AllErrors() []error { return m }
433
434
435
436
437 type RateLimitResponse_RateLimitValidationError struct {
438 field string
439 reason string
440 cause error
441 key bool
442 }
443
444
445 func (e RateLimitResponse_RateLimitValidationError) Field() string { return e.field }
446
447
448 func (e RateLimitResponse_RateLimitValidationError) Reason() string { return e.reason }
449
450
451 func (e RateLimitResponse_RateLimitValidationError) Cause() error { return e.cause }
452
453
454 func (e RateLimitResponse_RateLimitValidationError) Key() bool { return e.key }
455
456
457 func (e RateLimitResponse_RateLimitValidationError) ErrorName() string {
458 return "RateLimitResponse_RateLimitValidationError"
459 }
460
461
462 func (e RateLimitResponse_RateLimitValidationError) Error() string {
463 cause := ""
464 if e.cause != nil {
465 cause = fmt.Sprintf(" | caused by: %v", e.cause)
466 }
467
468 key := ""
469 if e.key {
470 key = "key for "
471 }
472
473 return fmt.Sprintf(
474 "invalid %sRateLimitResponse_RateLimit.%s: %s%s",
475 key,
476 e.field,
477 e.reason,
478 cause)
479 }
480
481 var _ error = RateLimitResponse_RateLimitValidationError{}
482
483 var _ interface {
484 Field() string
485 Reason() string
486 Key() bool
487 Cause() error
488 ErrorName() string
489 } = RateLimitResponse_RateLimitValidationError{}
490
491
492
493
494
495 func (m *RateLimitResponse_DescriptorStatus) Validate() error {
496 return m.validate(false)
497 }
498
499
500
501
502
503 func (m *RateLimitResponse_DescriptorStatus) ValidateAll() error {
504 return m.validate(true)
505 }
506
507 func (m *RateLimitResponse_DescriptorStatus) validate(all bool) error {
508 if m == nil {
509 return nil
510 }
511
512 var errors []error
513
514
515
516 if all {
517 switch v := interface{}(m.GetCurrentLimit()).(type) {
518 case interface{ ValidateAll() error }:
519 if err := v.ValidateAll(); err != nil {
520 errors = append(errors, RateLimitResponse_DescriptorStatusValidationError{
521 field: "CurrentLimit",
522 reason: "embedded message failed validation",
523 cause: err,
524 })
525 }
526 case interface{ Validate() error }:
527 if err := v.Validate(); err != nil {
528 errors = append(errors, RateLimitResponse_DescriptorStatusValidationError{
529 field: "CurrentLimit",
530 reason: "embedded message failed validation",
531 cause: err,
532 })
533 }
534 }
535 } else if v, ok := interface{}(m.GetCurrentLimit()).(interface{ Validate() error }); ok {
536 if err := v.Validate(); err != nil {
537 return RateLimitResponse_DescriptorStatusValidationError{
538 field: "CurrentLimit",
539 reason: "embedded message failed validation",
540 cause: err,
541 }
542 }
543 }
544
545
546
547 if len(errors) > 0 {
548 return RateLimitResponse_DescriptorStatusMultiError(errors)
549 }
550
551 return nil
552 }
553
554
555
556
557
558 type RateLimitResponse_DescriptorStatusMultiError []error
559
560
561 func (m RateLimitResponse_DescriptorStatusMultiError) Error() string {
562 var msgs []string
563 for _, err := range m {
564 msgs = append(msgs, err.Error())
565 }
566 return strings.Join(msgs, "; ")
567 }
568
569
570 func (m RateLimitResponse_DescriptorStatusMultiError) AllErrors() []error { return m }
571
572
573
574
575 type RateLimitResponse_DescriptorStatusValidationError struct {
576 field string
577 reason string
578 cause error
579 key bool
580 }
581
582
583 func (e RateLimitResponse_DescriptorStatusValidationError) Field() string { return e.field }
584
585
586 func (e RateLimitResponse_DescriptorStatusValidationError) Reason() string { return e.reason }
587
588
589 func (e RateLimitResponse_DescriptorStatusValidationError) Cause() error { return e.cause }
590
591
592 func (e RateLimitResponse_DescriptorStatusValidationError) Key() bool { return e.key }
593
594
595 func (e RateLimitResponse_DescriptorStatusValidationError) ErrorName() string {
596 return "RateLimitResponse_DescriptorStatusValidationError"
597 }
598
599
600 func (e RateLimitResponse_DescriptorStatusValidationError) Error() string {
601 cause := ""
602 if e.cause != nil {
603 cause = fmt.Sprintf(" | caused by: %v", e.cause)
604 }
605
606 key := ""
607 if e.key {
608 key = "key for "
609 }
610
611 return fmt.Sprintf(
612 "invalid %sRateLimitResponse_DescriptorStatus.%s: %s%s",
613 key,
614 e.field,
615 e.reason,
616 cause)
617 }
618
619 var _ error = RateLimitResponse_DescriptorStatusValidationError{}
620
621 var _ interface {
622 Field() string
623 Reason() string
624 Key() bool
625 Cause() error
626 ErrorName() string
627 } = RateLimitResponse_DescriptorStatusValidationError{}
628
View as plain text