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