Debian Codegraph @

envoy/extensions/matching/input_matchers/ip/v3/ip.pb.validate.go

raw
1 //go:build !disable_pgv
2 // Code generated by protoc-gen-validate. DO NOT EDIT.
3 // source: envoy/extensions/matching/input_matchers/ip/v3/ip.proto
4
5 package ipv3
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 Ip with the rules defined in the proto
40 // definition for this message. If any rules are violated, the first error
41 // encountered is returned, or nil if there are no violations.
42 func (m *Ip) Validate() error {
43 return m.validate(false)
44 }
45
46 // ValidateAll checks the field values on Ip 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 IpMultiError, or nil if none found.
49 func (m *Ip) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *Ip) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if len(m.GetCidrRanges()) < 1 {
61 err := IpValidationError{
62 field: "CidrRanges",
63 reason: "value must contain at least 1 item(s)",
64 }
65 if !all {
66 return err
67 }
68 errors = append(errors, err)
69 }
70
71 for idx, item := range m.GetCidrRanges() {
72 _, _ = idx, item
73
74 if all {
75 switch v := interface{}(item).(type) {
76 case interface{ ValidateAll() error }:
77 if err := v.ValidateAll(); err != nil {
78 errors = append(errors, IpValidationError{
79 field: fmt.Sprintf("CidrRanges[%v]", idx),
80 reason: "embedded message failed validation",
81 cause: err,
82 })
83 }
84 case interface{ Validate() error }:
85 if err := v.Validate(); err != nil {
86 errors = append(errors, IpValidationError{
87 field: fmt.Sprintf("CidrRanges[%v]", idx),
88 reason: "embedded message failed validation",
89 cause: err,
90 })
91 }
92 }
93 } else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
94 if err := v.Validate(); err != nil {
95 return IpValidationError{
96 field: fmt.Sprintf("CidrRanges[%v]", idx),
97 reason: "embedded message failed validation",
98 cause: err,
99 }
100 }
101 }
102
103 }
104
105 if utf8.RuneCountInString(m.GetStatPrefix()) < 1 {
106 err := IpValidationError{
107 field: "StatPrefix",
108 reason: "value length must be at least 1 runes",
109 }
110 if !all {
111 return err
112 }
113 errors = append(errors, err)
114 }
115
116 if len(errors) > 0 {
117 return IpMultiError(errors)
118 }
119
120 return nil
121 }
122
123 // IpMultiError is an error wrapping multiple validation errors returned by
124 // Ip.ValidateAll() if the designated constraints aren't met.
125 type IpMultiError []error
126
127 // Error returns a concatenation of all the error messages it wraps.
128 func (m IpMultiError) Error() string {
129 var msgs []string
130 for _, err := range m {
131 msgs = append(msgs, err.Error())
132 }
133 return strings.Join(msgs, "; ")
134 }
135
136 // AllErrors returns a list of validation violation errors.
137 func (m IpMultiError) AllErrors() []error { return m }
138
139 // IpValidationError is the validation error returned by Ip.Validate if the
140 // designated constraints aren't met.
141 type IpValidationError struct {
142 field string
143 reason string
144 cause error
145 key bool
146 }
147
148 // Field function returns field value.
149 func (e IpValidationError) Field() string { return e.field }
150
151 // Reason function returns reason value.
152 func (e IpValidationError) Reason() string { return e.reason }
153
154 // Cause function returns cause value.
155 func (e IpValidationError) Cause() error { return e.cause }
156
157 // Key function returns key value.
158 func (e IpValidationError) Key() bool { return e.key }
159
160 // ErrorName returns error name.
161 func (e IpValidationError) ErrorName() string { return "IpValidationError" }
162
163 // Error satisfies the builtin error interface
164 func (e IpValidationError) Error() string {
165 cause := ""
166 if e.cause != nil {
167 cause = fmt.Sprintf(" | caused by: %v", e.cause)
168 }
169
170 key := ""
171 if e.key {
172 key = "key for "
173 }
174
175 return fmt.Sprintf(
176 "invalid %sIp.%s: %s%s",
177 key,
178 e.field,
179 e.reason,
180 cause)
181 }
182
183 var _ error = IpValidationError{}
184
185 var _ interface {
186 Field() string
187 Reason() string
188 Key() bool
189 Cause() error
190 ErrorName() string
191 } = IpValidationError{}