github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/extensions/matching/input_matchers/ip/v3/ip.pb.validate.go (about) 1 // Code generated by protoc-gen-validate. DO NOT EDIT. 2 // source: envoy/extensions/matching/input_matchers/ip/v3/ip.proto 3 4 package envoy_extensions_matching_input_matchers_ip_v3 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 Ip with the rules defined in the proto 37 // definition for this message. If any rules are violated, an error is returned. 38 func (m *Ip) Validate() error { 39 if m == nil { 40 return nil 41 } 42 43 if len(m.GetCidrRanges()) < 1 { 44 return IpValidationError{ 45 field: "CidrRanges", 46 reason: "value must contain at least 1 item(s)", 47 } 48 } 49 50 for idx, item := range m.GetCidrRanges() { 51 _, _ = idx, item 52 53 if v, ok := interface{}(item).(interface{ Validate() error }); ok { 54 if err := v.Validate(); err != nil { 55 return IpValidationError{ 56 field: fmt.Sprintf("CidrRanges[%v]", idx), 57 reason: "embedded message failed validation", 58 cause: err, 59 } 60 } 61 } 62 63 } 64 65 if utf8.RuneCountInString(m.GetStatPrefix()) < 1 { 66 return IpValidationError{ 67 field: "StatPrefix", 68 reason: "value length must be at least 1 runes", 69 } 70 } 71 72 return nil 73 } 74 75 // IpValidationError is the validation error returned by Ip.Validate if the 76 // designated constraints aren't met. 77 type IpValidationError struct { 78 field string 79 reason string 80 cause error 81 key bool 82 } 83 84 // Field function returns field value. 85 func (e IpValidationError) Field() string { return e.field } 86 87 // Reason function returns reason value. 88 func (e IpValidationError) Reason() string { return e.reason } 89 90 // Cause function returns cause value. 91 func (e IpValidationError) Cause() error { return e.cause } 92 93 // Key function returns key value. 94 func (e IpValidationError) Key() bool { return e.key } 95 96 // ErrorName returns error name. 97 func (e IpValidationError) ErrorName() string { return "IpValidationError" } 98 99 // Error satisfies the builtin error interface 100 func (e IpValidationError) Error() string { 101 cause := "" 102 if e.cause != nil { 103 cause = fmt.Sprintf(" | caused by: %v", e.cause) 104 } 105 106 key := "" 107 if e.key { 108 key = "key for " 109 } 110 111 return fmt.Sprintf( 112 "invalid %sIp.%s: %s%s", 113 key, 114 e.field, 115 e.reason, 116 cause) 117 } 118 119 var _ error = IpValidationError{} 120 121 var _ interface { 122 Field() string 123 Reason() string 124 Key() bool 125 Cause() error 126 ErrorName() string 127 } = IpValidationError{}