/pkg/api/envoy/api/v2/core/socket_option.pb.validate.go

https://github.com/datawire/ambassador · Go · 131 lines · 84 code · 27 blank · 20 comment · 7 complexity · 34a0ff4c1a71cf14b1c2973280cf939f MD5 · raw file

  1. // Code generated by protoc-gen-validate. DO NOT EDIT.
  2. // source: envoy/api/v2/core/socket_option.proto
  3. package envoy_api_v2_core
  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 _socket_option_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 SocketOption with the rules defined in
  34. // the proto definition for this message. If any rules are violated, an error
  35. // is returned.
  36. func (m *SocketOption) Validate() error {
  37. if m == nil {
  38. return nil
  39. }
  40. // no validation rules for Description
  41. // no validation rules for Level
  42. // no validation rules for Name
  43. if _, ok := SocketOption_SocketState_name[int32(m.GetState())]; !ok {
  44. return SocketOptionValidationError{
  45. field: "State",
  46. reason: "value must be one of the defined enum values",
  47. }
  48. }
  49. switch m.Value.(type) {
  50. case *SocketOption_IntValue:
  51. // no validation rules for IntValue
  52. case *SocketOption_BufValue:
  53. // no validation rules for BufValue
  54. default:
  55. return SocketOptionValidationError{
  56. field: "Value",
  57. reason: "value is required",
  58. }
  59. }
  60. return nil
  61. }
  62. // SocketOptionValidationError is the validation error returned by
  63. // SocketOption.Validate if the designated constraints aren't met.
  64. type SocketOptionValidationError struct {
  65. field string
  66. reason string
  67. cause error
  68. key bool
  69. }
  70. // Field function returns field value.
  71. func (e SocketOptionValidationError) Field() string { return e.field }
  72. // Reason function returns reason value.
  73. func (e SocketOptionValidationError) Reason() string { return e.reason }
  74. // Cause function returns cause value.
  75. func (e SocketOptionValidationError) Cause() error { return e.cause }
  76. // Key function returns key value.
  77. func (e SocketOptionValidationError) Key() bool { return e.key }
  78. // ErrorName returns error name.
  79. func (e SocketOptionValidationError) ErrorName() string { return "SocketOptionValidationError" }
  80. // Error satisfies the builtin error interface
  81. func (e SocketOptionValidationError) Error() string {
  82. cause := ""
  83. if e.cause != nil {
  84. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  85. }
  86. key := ""
  87. if e.key {
  88. key = "key for "
  89. }
  90. return fmt.Sprintf(
  91. "invalid %sSocketOption.%s: %s%s",
  92. key,
  93. e.field,
  94. e.reason,
  95. cause)
  96. }
  97. var _ error = SocketOptionValidationError{}
  98. var _ interface {
  99. Field() string
  100. Reason() string
  101. Key() bool
  102. Cause() error
  103. ErrorName() string
  104. } = SocketOptionValidationError{}