Debian Codegraph @

go/xds/core/v3/resource.pb.validate.go

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