Debian Codegraph @

envoy/extensions/load_balancing_policies/ring_hash/v3/ring_hash.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/ring_hash/v3/ring_hash.proto
4
5 package ring_hashv3
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 RingHash 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 *RingHash) Validate() error {
43 return m.validate(false)
44 }
45
46 // ValidateAll checks the field values on RingHash with the rules defined in
47 // the proto definition for this message. If any rules are violated, the
48 // result is a list of violation errors wrapped in RingHashMultiError, or nil
49 // if none found.
50 func (m *RingHash) ValidateAll() error {
51 return m.validate(true)
52 }
53
54 func (m *RingHash) validate(all bool) error {
55 if m == nil {
56 return nil
57 }
58
59 var errors []error
60
61 if _, ok := RingHash_HashFunction_name[int32(m.GetHashFunction())]; !ok {
62 err := RingHashValidationError{
63 field: "HashFunction",
64 reason: "value must be one of the defined enum values",
65 }
66 if !all {
67 return err
68 }
69 errors = append(errors, err)
70 }
71
72 if wrapper := m.GetMinimumRingSize(); wrapper != nil {
73
74 if val := wrapper.GetValue(); val < 1 || val > 8388608 {
75 err := RingHashValidationError{
76 field: "MinimumRingSize",
77 reason: "value must be inside range [1, 8388608]",
78 }
79 if !all {
80 return err
81 }
82 errors = append(errors, err)
83 }
84
85 }
86
87 if wrapper := m.GetMaximumRingSize(); wrapper != nil {
88
89 if wrapper.GetValue() > 8388608 {
90 err := RingHashValidationError{
91 field: "MaximumRingSize",
92 reason: "value must be less than or equal to 8388608",
93 }
94 if !all {
95 return err
96 }
97 errors = append(errors, err)
98 }
99
100 }
101
102 // no validation rules for UseHostnameForHashing
103
104 if wrapper := m.GetHashBalanceFactor(); wrapper != nil {
105
106 if wrapper.GetValue() < 100 {
107 err := RingHashValidationError{
108 field: "HashBalanceFactor",
109 reason: "value must be greater than or equal to 100",
110 }
111 if !all {
112 return err
113 }
114 errors = append(errors, err)
115 }
116
117 }
118
119 if all {
120 switch v := interface{}(m.GetConsistentHashingLbConfig()).(type) {
121 case interface{ ValidateAll() error }:
122 if err := v.ValidateAll(); err != nil {
123 errors = append(errors, RingHashValidationError{
124 field: "ConsistentHashingLbConfig",
125 reason: "embedded message failed validation",
126 cause: err,
127 })
128 }
129 case interface{ Validate() error }:
130 if err := v.Validate(); err != nil {
131 errors = append(errors, RingHashValidationError{
132 field: "ConsistentHashingLbConfig",
133 reason: "embedded message failed validation",
134 cause: err,
135 })
136 }
137 }
138 } else if v, ok := interface{}(m.GetConsistentHashingLbConfig()).(interface{ Validate() error }); ok {
139 if err := v.Validate(); err != nil {
140 return RingHashValidationError{
141 field: "ConsistentHashingLbConfig",
142 reason: "embedded message failed validation",
143 cause: err,
144 }
145 }
146 }
147
148 if all {
149 switch v := interface{}(m.GetLocalityWeightedLbConfig()).(type) {
150 case interface{ ValidateAll() error }:
151 if err := v.ValidateAll(); err != nil {
152 errors = append(errors, RingHashValidationError{
153 field: "LocalityWeightedLbConfig",
154 reason: "embedded message failed validation",
155 cause: err,
156 })
157 }
158 case interface{ Validate() error }:
159 if err := v.Validate(); err != nil {
160 errors = append(errors, RingHashValidationError{
161 field: "LocalityWeightedLbConfig",
162 reason: "embedded message failed validation",
163 cause: err,
164 })
165 }
166 }
167 } else if v, ok := interface{}(m.GetLocalityWeightedLbConfig()).(interface{ Validate() error }); ok {
168 if err := v.Validate(); err != nil {
169 return RingHashValidationError{
170 field: "LocalityWeightedLbConfig",
171 reason: "embedded message failed validation",
172 cause: err,
173 }
174 }
175 }
176
177 if len(errors) > 0 {
178 return RingHashMultiError(errors)
179 }
180
181 return nil
182 }
183
184 // RingHashMultiError is an error wrapping multiple validation errors returned
185 // by RingHash.ValidateAll() if the designated constraints aren't met.
186 type RingHashMultiError []error
187
188 // Error returns a concatenation of all the error messages it wraps.
189 func (m RingHashMultiError) Error() string {
190 var msgs []string
191 for _, err := range m {
192 msgs = append(msgs, err.Error())
193 }
194 return strings.Join(msgs, "; ")
195 }
196
197 // AllErrors returns a list of validation violation errors.
198 func (m RingHashMultiError) AllErrors() []error { return m }
199
200 // RingHashValidationError is the validation error returned by
201 // RingHash.Validate if the designated constraints aren't met.
202 type RingHashValidationError struct {
203 field string
204 reason string
205 cause error
206 key bool
207 }
208
209 // Field function returns field value.
210 func (e RingHashValidationError) Field() string { return e.field }
211
212 // Reason function returns reason value.
213 func (e RingHashValidationError) Reason() string { return e.reason }
214
215 // Cause function returns cause value.
216 func (e RingHashValidationError) Cause() error { return e.cause }
217
218 // Key function returns key value.
219 func (e RingHashValidationError) Key() bool { return e.key }
220
221 // ErrorName returns error name.
222 func (e RingHashValidationError) ErrorName() string { return "RingHashValidationError" }
223
224 // Error satisfies the builtin error interface
225 func (e RingHashValidationError) Error() string {
226 cause := ""
227 if e.cause != nil {
228 cause = fmt.Sprintf(" | caused by: %v", e.cause)
229 }
230
231 key := ""
232 if e.key {
233 key = "key for "
234 }
235
236 return fmt.Sprintf(
237 "invalid %sRingHash.%s: %s%s",
238 key,
239 e.field,
240 e.reason,
241 cause)
242 }
243
244 var _ error = RingHashValidationError{}
245
246 var _ interface {
247 Field() string
248 Reason() string
249 Key() bool
250 Cause() error
251 ErrorName() string
252 } = RingHashValidationError{}