Debian Codegraph @

go/xds/type/v3/typed_struct.pb.validate.go

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