/pkg/api/envoy/type/matcher/v3/metadata.pb.validate.go

https://github.com/datawire/ambassador · Go · 235 lines · 165 code · 43 blank · 27 comment · 23 complexity · 6aeb13d77f831812b791069766951a84 MD5 · raw file

  1. // Code generated by protoc-gen-validate. DO NOT EDIT.
  2. // source: envoy/type/matcher/v3/metadata.proto
  3. package envoy_type_matcher_v3
  4. import (
  5. "bytes"
  6. "errors"
  7. "fmt"
  8. "net"
  9. "net/mail"
  10. "net/url"
  11. "regexp"
  12. "strings"
  13. "time"
  14. "unicode/utf8"
  15. "github.com/golang/protobuf/ptypes"
  16. )
  17. // ensure the imports are used
  18. var (
  19. _ = bytes.MinRead
  20. _ = errors.New("")
  21. _ = fmt.Print
  22. _ = utf8.UTFMax
  23. _ = (*regexp.Regexp)(nil)
  24. _ = (*strings.Reader)(nil)
  25. _ = net.IPv4len
  26. _ = time.Duration(0)
  27. _ = (*url.URL)(nil)
  28. _ = (*mail.Address)(nil)
  29. _ = ptypes.DynamicAny{}
  30. )
  31. // define the regex for a UUID once up-front
  32. var _metadata_uuidPattern = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
  33. // Validate checks the field values on MetadataMatcher with the rules defined
  34. // in the proto definition for this message. If any rules are violated, an
  35. // error is returned.
  36. func (m *MetadataMatcher) Validate() error {
  37. if m == nil {
  38. return nil
  39. }
  40. if len(m.GetFilter()) < 1 {
  41. return MetadataMatcherValidationError{
  42. field: "Filter",
  43. reason: "value length must be at least 1 bytes",
  44. }
  45. }
  46. if len(m.GetPath()) < 1 {
  47. return MetadataMatcherValidationError{
  48. field: "Path",
  49. reason: "value must contain at least 1 item(s)",
  50. }
  51. }
  52. for idx, item := range m.GetPath() {
  53. _, _ = idx, item
  54. if v, ok := interface{}(item).(interface{ Validate() error }); ok {
  55. if err := v.Validate(); err != nil {
  56. return MetadataMatcherValidationError{
  57. field: fmt.Sprintf("Path[%v]", idx),
  58. reason: "embedded message failed validation",
  59. cause: err,
  60. }
  61. }
  62. }
  63. }
  64. if m.GetValue() == nil {
  65. return MetadataMatcherValidationError{
  66. field: "Value",
  67. reason: "value is required",
  68. }
  69. }
  70. if v, ok := interface{}(m.GetValue()).(interface{ Validate() error }); ok {
  71. if err := v.Validate(); err != nil {
  72. return MetadataMatcherValidationError{
  73. field: "Value",
  74. reason: "embedded message failed validation",
  75. cause: err,
  76. }
  77. }
  78. }
  79. return nil
  80. }
  81. // MetadataMatcherValidationError is the validation error returned by
  82. // MetadataMatcher.Validate if the designated constraints aren't met.
  83. type MetadataMatcherValidationError struct {
  84. field string
  85. reason string
  86. cause error
  87. key bool
  88. }
  89. // Field function returns field value.
  90. func (e MetadataMatcherValidationError) Field() string { return e.field }
  91. // Reason function returns reason value.
  92. func (e MetadataMatcherValidationError) Reason() string { return e.reason }
  93. // Cause function returns cause value.
  94. func (e MetadataMatcherValidationError) Cause() error { return e.cause }
  95. // Key function returns key value.
  96. func (e MetadataMatcherValidationError) Key() bool { return e.key }
  97. // ErrorName returns error name.
  98. func (e MetadataMatcherValidationError) ErrorName() string { return "MetadataMatcherValidationError" }
  99. // Error satisfies the builtin error interface
  100. func (e MetadataMatcherValidationError) Error() string {
  101. cause := ""
  102. if e.cause != nil {
  103. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  104. }
  105. key := ""
  106. if e.key {
  107. key = "key for "
  108. }
  109. return fmt.Sprintf(
  110. "invalid %sMetadataMatcher.%s: %s%s",
  111. key,
  112. e.field,
  113. e.reason,
  114. cause)
  115. }
  116. var _ error = MetadataMatcherValidationError{}
  117. var _ interface {
  118. Field() string
  119. Reason() string
  120. Key() bool
  121. Cause() error
  122. ErrorName() string
  123. } = MetadataMatcherValidationError{}
  124. // Validate checks the field values on MetadataMatcher_PathSegment with the
  125. // rules defined in the proto definition for this message. If any rules are
  126. // violated, an error is returned.
  127. func (m *MetadataMatcher_PathSegment) Validate() error {
  128. if m == nil {
  129. return nil
  130. }
  131. switch m.Segment.(type) {
  132. case *MetadataMatcher_PathSegment_Key:
  133. if len(m.GetKey()) < 1 {
  134. return MetadataMatcher_PathSegmentValidationError{
  135. field: "Key",
  136. reason: "value length must be at least 1 bytes",
  137. }
  138. }
  139. default:
  140. return MetadataMatcher_PathSegmentValidationError{
  141. field: "Segment",
  142. reason: "value is required",
  143. }
  144. }
  145. return nil
  146. }
  147. // MetadataMatcher_PathSegmentValidationError is the validation error returned
  148. // by MetadataMatcher_PathSegment.Validate if the designated constraints
  149. // aren't met.
  150. type MetadataMatcher_PathSegmentValidationError struct {
  151. field string
  152. reason string
  153. cause error
  154. key bool
  155. }
  156. // Field function returns field value.
  157. func (e MetadataMatcher_PathSegmentValidationError) Field() string { return e.field }
  158. // Reason function returns reason value.
  159. func (e MetadataMatcher_PathSegmentValidationError) Reason() string { return e.reason }
  160. // Cause function returns cause value.
  161. func (e MetadataMatcher_PathSegmentValidationError) Cause() error { return e.cause }
  162. // Key function returns key value.
  163. func (e MetadataMatcher_PathSegmentValidationError) Key() bool { return e.key }
  164. // ErrorName returns error name.
  165. func (e MetadataMatcher_PathSegmentValidationError) ErrorName() string {
  166. return "MetadataMatcher_PathSegmentValidationError"
  167. }
  168. // Error satisfies the builtin error interface
  169. func (e MetadataMatcher_PathSegmentValidationError) Error() string {
  170. cause := ""
  171. if e.cause != nil {
  172. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  173. }
  174. key := ""
  175. if e.key {
  176. key = "key for "
  177. }
  178. return fmt.Sprintf(
  179. "invalid %sMetadataMatcher_PathSegment.%s: %s%s",
  180. key,
  181. e.field,
  182. e.reason,
  183. cause)
  184. }
  185. var _ error = MetadataMatcher_PathSegmentValidationError{}
  186. var _ interface {
  187. Field() string
  188. Reason() string
  189. Key() bool
  190. Cause() error
  191. ErrorName() string
  192. } = MetadataMatcher_PathSegmentValidationError{}