Debian Codegraph @

go/xds/type/matcher/v3/cel.pb.validate.go

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