github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/type/matcher/struct.pb.validate.go (about) 1 // Code generated by protoc-gen-validate. DO NOT EDIT. 2 // source: envoy/type/matcher/struct.proto 3 4 package envoy_type_matcher 5 6 import ( 7 "bytes" 8 "errors" 9 "fmt" 10 "net" 11 "net/mail" 12 "net/url" 13 "regexp" 14 "strings" 15 "time" 16 "unicode/utf8" 17 18 "google.golang.org/protobuf/types/known/anypb" 19 ) 20 21 // ensure the imports are used 22 var ( 23 _ = bytes.MinRead 24 _ = errors.New("") 25 _ = fmt.Print 26 _ = utf8.UTFMax 27 _ = (*regexp.Regexp)(nil) 28 _ = (*strings.Reader)(nil) 29 _ = net.IPv4len 30 _ = time.Duration(0) 31 _ = (*url.URL)(nil) 32 _ = (*mail.Address)(nil) 33 _ = anypb.Any{} 34 ) 35 36 // Validate checks the field values on StructMatcher with the rules defined in 37 // the proto definition for this message. If any rules are violated, an error 38 // is returned. 39 func (m *StructMatcher) Validate() error { 40 if m == nil { 41 return nil 42 } 43 44 if len(m.GetPath()) < 1 { 45 return StructMatcherValidationError{ 46 field: "Path", 47 reason: "value must contain at least 1 item(s)", 48 } 49 } 50 51 for idx, item := range m.GetPath() { 52 _, _ = idx, item 53 54 if v, ok := interface{}(item).(interface{ Validate() error }); ok { 55 if err := v.Validate(); err != nil { 56 return StructMatcherValidationError{ 57 field: fmt.Sprintf("Path[%v]", idx), 58 reason: "embedded message failed validation", 59 cause: err, 60 } 61 } 62 } 63 64 } 65 66 if m.GetValue() == nil { 67 return StructMatcherValidationError{ 68 field: "Value", 69 reason: "value is required", 70 } 71 } 72 73 if v, ok := interface{}(m.GetValue()).(interface{ Validate() error }); ok { 74 if err := v.Validate(); err != nil { 75 return StructMatcherValidationError{ 76 field: "Value", 77 reason: "embedded message failed validation", 78 cause: err, 79 } 80 } 81 } 82 83 return nil 84 } 85 86 // StructMatcherValidationError is the validation error returned by 87 // StructMatcher.Validate if the designated constraints aren't met. 88 type StructMatcherValidationError struct { 89 field string 90 reason string 91 cause error 92 key bool 93 } 94 95 // Field function returns field value. 96 func (e StructMatcherValidationError) Field() string { return e.field } 97 98 // Reason function returns reason value. 99 func (e StructMatcherValidationError) Reason() string { return e.reason } 100 101 // Cause function returns cause value. 102 func (e StructMatcherValidationError) Cause() error { return e.cause } 103 104 // Key function returns key value. 105 func (e StructMatcherValidationError) Key() bool { return e.key } 106 107 // ErrorName returns error name. 108 func (e StructMatcherValidationError) ErrorName() string { return "StructMatcherValidationError" } 109 110 // Error satisfies the builtin error interface 111 func (e StructMatcherValidationError) Error() string { 112 cause := "" 113 if e.cause != nil { 114 cause = fmt.Sprintf(" | caused by: %v", e.cause) 115 } 116 117 key := "" 118 if e.key { 119 key = "key for " 120 } 121 122 return fmt.Sprintf( 123 "invalid %sStructMatcher.%s: %s%s", 124 key, 125 e.field, 126 e.reason, 127 cause) 128 } 129 130 var _ error = StructMatcherValidationError{} 131 132 var _ interface { 133 Field() string 134 Reason() string 135 Key() bool 136 Cause() error 137 ErrorName() string 138 } = StructMatcherValidationError{} 139 140 // Validate checks the field values on StructMatcher_PathSegment with the rules 141 // defined in the proto definition for this message. If any rules are 142 // violated, an error is returned. 143 func (m *StructMatcher_PathSegment) Validate() error { 144 if m == nil { 145 return nil 146 } 147 148 switch m.Segment.(type) { 149 150 case *StructMatcher_PathSegment_Key: 151 152 if utf8.RuneCountInString(m.GetKey()) < 1 { 153 return StructMatcher_PathSegmentValidationError{ 154 field: "Key", 155 reason: "value length must be at least 1 runes", 156 } 157 } 158 159 default: 160 return StructMatcher_PathSegmentValidationError{ 161 field: "Segment", 162 reason: "value is required", 163 } 164 165 } 166 167 return nil 168 } 169 170 // StructMatcher_PathSegmentValidationError is the validation error returned by 171 // StructMatcher_PathSegment.Validate if the designated constraints aren't met. 172 type StructMatcher_PathSegmentValidationError struct { 173 field string 174 reason string 175 cause error 176 key bool 177 } 178 179 // Field function returns field value. 180 func (e StructMatcher_PathSegmentValidationError) Field() string { return e.field } 181 182 // Reason function returns reason value. 183 func (e StructMatcher_PathSegmentValidationError) Reason() string { return e.reason } 184 185 // Cause function returns cause value. 186 func (e StructMatcher_PathSegmentValidationError) Cause() error { return e.cause } 187 188 // Key function returns key value. 189 func (e StructMatcher_PathSegmentValidationError) Key() bool { return e.key } 190 191 // ErrorName returns error name. 192 func (e StructMatcher_PathSegmentValidationError) ErrorName() string { 193 return "StructMatcher_PathSegmentValidationError" 194 } 195 196 // Error satisfies the builtin error interface 197 func (e StructMatcher_PathSegmentValidationError) Error() string { 198 cause := "" 199 if e.cause != nil { 200 cause = fmt.Sprintf(" | caused by: %v", e.cause) 201 } 202 203 key := "" 204 if e.key { 205 key = "key for " 206 } 207 208 return fmt.Sprintf( 209 "invalid %sStructMatcher_PathSegment.%s: %s%s", 210 key, 211 e.field, 212 e.reason, 213 cause) 214 } 215 216 var _ error = StructMatcher_PathSegmentValidationError{} 217 218 var _ interface { 219 Field() string 220 Reason() string 221 Key() bool 222 Cause() error 223 ErrorName() string 224 } = StructMatcher_PathSegmentValidationError{}