/pkg/api/envoy/config/core/v3/http_uri.pb.validate.go

https://github.com/datawire/ambassador · Go · 155 lines · 112 code · 29 blank · 14 comment · 15 complexity · d45878b2328c14a43d85a74d05488527 MD5 · raw file

  1. // Code generated by protoc-gen-validate. DO NOT EDIT.
  2. // source: envoy/config/core/v3/http_uri.proto
  3. package envoy_config_core_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 _http_uri_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 HttpUri with the rules defined in the
  34. // proto definition for this message. If any rules are violated, an error is returned.
  35. func (m *HttpUri) Validate() error {
  36. if m == nil {
  37. return nil
  38. }
  39. if len(m.GetUri()) < 1 {
  40. return HttpUriValidationError{
  41. field: "Uri",
  42. reason: "value length must be at least 1 bytes",
  43. }
  44. }
  45. if m.GetTimeout() == nil {
  46. return HttpUriValidationError{
  47. field: "Timeout",
  48. reason: "value is required",
  49. }
  50. }
  51. if d := m.GetTimeout(); d != nil {
  52. dur, err := ptypes.Duration(d)
  53. if err != nil {
  54. return HttpUriValidationError{
  55. field: "Timeout",
  56. reason: "value is not a valid duration",
  57. cause: err,
  58. }
  59. }
  60. gte := time.Duration(0*time.Second + 0*time.Nanosecond)
  61. if dur < gte {
  62. return HttpUriValidationError{
  63. field: "Timeout",
  64. reason: "value must be greater than or equal to 0s",
  65. }
  66. }
  67. }
  68. switch m.HttpUpstreamType.(type) {
  69. case *HttpUri_Cluster:
  70. if len(m.GetCluster()) < 1 {
  71. return HttpUriValidationError{
  72. field: "Cluster",
  73. reason: "value length must be at least 1 bytes",
  74. }
  75. }
  76. default:
  77. return HttpUriValidationError{
  78. field: "HttpUpstreamType",
  79. reason: "value is required",
  80. }
  81. }
  82. return nil
  83. }
  84. // HttpUriValidationError is the validation error returned by HttpUri.Validate
  85. // if the designated constraints aren't met.
  86. type HttpUriValidationError struct {
  87. field string
  88. reason string
  89. cause error
  90. key bool
  91. }
  92. // Field function returns field value.
  93. func (e HttpUriValidationError) Field() string { return e.field }
  94. // Reason function returns reason value.
  95. func (e HttpUriValidationError) Reason() string { return e.reason }
  96. // Cause function returns cause value.
  97. func (e HttpUriValidationError) Cause() error { return e.cause }
  98. // Key function returns key value.
  99. func (e HttpUriValidationError) Key() bool { return e.key }
  100. // ErrorName returns error name.
  101. func (e HttpUriValidationError) ErrorName() string { return "HttpUriValidationError" }
  102. // Error satisfies the builtin error interface
  103. func (e HttpUriValidationError) Error() string {
  104. cause := ""
  105. if e.cause != nil {
  106. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  107. }
  108. key := ""
  109. if e.key {
  110. key = "key for "
  111. }
  112. return fmt.Sprintf(
  113. "invalid %sHttpUri.%s: %s%s",
  114. key,
  115. e.field,
  116. e.reason,
  117. cause)
  118. }
  119. var _ error = HttpUriValidationError{}
  120. var _ interface {
  121. Field() string
  122. Reason() string
  123. Key() bool
  124. Cause() error
  125. ErrorName() string
  126. } = HttpUriValidationError{}