Debian Codegraph @

envoy/extensions/load_balancing_policies/maglev/v3/maglev.pb.validate.go

raw
1 //go:build !disable_pgv
2 // Code generated by protoc-gen-validate. DO NOT EDIT.
3 // source: envoy/extensions/load_balancing_policies/maglev/v3/maglev.proto
4
5 package maglevv3
6
7 import (
8 "bytes"
9 "errors"
10 "fmt"
11 "net"
12 "net/mail"
13 "net/url"
14 "regexp"
15 "sort"
16 "strings"
17 "time"
18 "unicode/utf8"
19
20 "google.golang.org/protobuf/types/known/anypb"
21 )
22
23 // ensure the imports are used
24 var (
25 _ = bytes.MinRead
26 _ = errors.New("")
27 _ = fmt.Print
28 _ = utf8.UTFMax
29 _ = (*regexp.Regexp)(nil)
30 _ = (*strings.Reader)(nil)
31 _ = net.IPv4len
32 _ = time.Duration(0)
33 _ = (*url.URL)(nil)
34 _ = (*mail.Address)(nil)
35 _ = anypb.Any{}
36 _ = sort.Sort
37 )
38
39 // Validate checks the field values on Maglev with the rules defined in the
40 // proto definition for this message. If any rules are violated, the first
41 // error encountered is returned, or nil if there are no violations.
42 func (m *Maglev) Validate() error {
43 return m.validate(false)
44 }
45
46 // ValidateAll checks the field values on Maglev with the rules defined in the
47 // proto definition for this message. If any rules are violated, the result is
48 // a list of violation errors wrapped in MaglevMultiError, or nil if none found.
49 func (m *Maglev) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *Maglev) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if wrapper := m.GetTableSize(); wrapper != nil {
61
62 if wrapper.GetValue() > 5000011 {
63 err := MaglevValidationError{
64 field: "TableSize",
65 reason: "value must be less than or equal to 5000011",
66 }
67 if !all {
68 return err
69 }
70 errors = append(errors, err)
71 }
72
73 }
74
75 if all {
76 switch v := interface{}(m.GetConsistentHashingLbConfig()).(type) {
77 case interface{ ValidateAll() error }:
78 if err := v.ValidateAll(); err != nil {
79 errors = append(errors, MaglevValidationError{
80 field: "ConsistentHashingLbConfig",
81 reason: "embedded message failed validation",
82 cause: err,
83 })
84 }
85 case interface{ Validate() error }:
86 if err := v.Validate(); err != nil {
87 errors = append(errors, MaglevValidationError{
88 field: "ConsistentHashingLbConfig",
89 reason: "embedded message failed validation",
90 cause: err,
91 })
92 }
93 }
94 } else if v, ok := interface{}(m.GetConsistentHashingLbConfig()).(interface{ Validate() error }); ok {
95 if err := v.Validate(); err != nil {
96 return MaglevValidationError{
97 field: "ConsistentHashingLbConfig",
98 reason: "embedded message failed validation",
99 cause: err,
100 }
101 }
102 }
103
104 if all {
105 switch v := interface{}(m.GetLocalityWeightedLbConfig()).(type) {
106 case interface{ ValidateAll() error }:
107 if err := v.ValidateAll(); err != nil {
108 errors = append(errors, MaglevValidationError{
109 field: "LocalityWeightedLbConfig",
110 reason: "embedded message failed validation",
111 cause: err,
112 })
113 }
114 case interface{ Validate() error }:
115 if err := v.Validate(); err != nil {
116 errors = append(errors, MaglevValidationError{
117 field: "LocalityWeightedLbConfig",
118 reason: "embedded message failed validation",
119 cause: err,
120 })
121 }
122 }
123 } else if v, ok := interface{}(m.GetLocalityWeightedLbConfig()).(interface{ Validate() error }); ok {
124 if err := v.Validate(); err != nil {
125 return MaglevValidationError{
126 field: "LocalityWeightedLbConfig",
127 reason: "embedded message failed validation",
128 cause: err,
129 }
130 }
131 }
132
133 if len(errors) > 0 {
134 return MaglevMultiError(errors)
135 }
136
137 return nil
138 }
139
140 // MaglevMultiError is an error wrapping multiple validation errors returned by
141 // Maglev.ValidateAll() if the designated constraints aren't met.
142 type MaglevMultiError []error
143
144 // Error returns a concatenation of all the error messages it wraps.
145 func (m MaglevMultiError) Error() string {
146 var msgs []string
147 for _, err := range m {
148 msgs = append(msgs, err.Error())
149 }
150 return strings.Join(msgs, "; ")
151 }
152
153 // AllErrors returns a list of validation violation errors.
154 func (m MaglevMultiError) AllErrors() []error { return m }
155
156 // MaglevValidationError is the validation error returned by Maglev.Validate if
157 // the designated constraints aren't met.
158 type MaglevValidationError struct {
159 field string
160 reason string
161 cause error
162 key bool
163 }
164
165 // Field function returns field value.
166 func (e MaglevValidationError) Field() string { return e.field }
167
168 // Reason function returns reason value.
169 func (e MaglevValidationError) Reason() string { return e.reason }
170
171 // Cause function returns cause value.
172 func (e MaglevValidationError) Cause() error { return e.cause }
173
174 // Key function returns key value.
175 func (e MaglevValidationError) Key() bool { return e.key }
176
177 // ErrorName returns error name.
178 func (e MaglevValidationError) ErrorName() string { return "MaglevValidationError" }
179
180 // Error satisfies the builtin error interface
181 func (e MaglevValidationError) Error() string {
182 cause := ""
183 if e.cause != nil {
184 cause = fmt.Sprintf(" | caused by: %v", e.cause)
185 }
186
187 key := ""
188 if e.key {
189 key = "key for "
190 }
191
192 return fmt.Sprintf(
193 "invalid %sMaglev.%s: %s%s",
194 key,
195 e.field,
196 e.reason,
197 cause)
198 }
199
200 var _ error = MaglevValidationError{}
201
202 var _ interface {
203 Field() string
204 Reason() string
205 Key() bool
206 Cause() error
207 ErrorName() string
208 } = MaglevValidationError{}