go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/quotapb/op.pb.validate.go (about) 1 // Code generated by protoc-gen-validate. DO NOT EDIT. 2 // source: go.chromium.org/luci/server/quota/quotapb/op.proto 3 4 package quotapb 5 6 import ( 7 "bytes" 8 "errors" 9 "fmt" 10 "net" 11 "net/mail" 12 "net/url" 13 "regexp" 14 "sort" 15 "strings" 16 "time" 17 "unicode/utf8" 18 19 "google.golang.org/protobuf/types/known/anypb" 20 ) 21 22 // ensure the imports are used 23 var ( 24 _ = bytes.MinRead 25 _ = errors.New("") 26 _ = fmt.Print 27 _ = utf8.UTFMax 28 _ = (*regexp.Regexp)(nil) 29 _ = (*strings.Reader)(nil) 30 _ = net.IPv4len 31 _ = time.Duration(0) 32 _ = (*url.URL)(nil) 33 _ = (*mail.Address)(nil) 34 _ = anypb.Any{} 35 _ = sort.Sort 36 ) 37 38 // Validate checks the field values on Op with the rules defined in the proto 39 // definition for this message. If any rules are violated, the first error 40 // encountered is returned, or nil if there are no violations. 41 func (m *Op) Validate() error { 42 return m.validate(false) 43 } 44 45 // ValidateAll checks the field values on Op with the rules defined in the 46 // proto definition for this message. If any rules are violated, the result is 47 // a list of violation errors wrapped in OpMultiError, or nil if none found. 48 func (m *Op) ValidateAll() error { 49 return m.validate(true) 50 } 51 52 func (m *Op) validate(all bool) error { 53 if m == nil { 54 return nil 55 } 56 57 var errors []error 58 59 if m.GetAccountId() == nil { 60 err := OpValidationError{ 61 field: "AccountId", 62 reason: "value is required", 63 } 64 if !all { 65 return err 66 } 67 errors = append(errors, err) 68 } 69 70 if all { 71 switch v := interface{}(m.GetAccountId()).(type) { 72 case interface{ ValidateAll() error }: 73 if err := v.ValidateAll(); err != nil { 74 errors = append(errors, OpValidationError{ 75 field: "AccountId", 76 reason: "embedded message failed validation", 77 cause: err, 78 }) 79 } 80 case interface{ Validate() error }: 81 if err := v.Validate(); err != nil { 82 errors = append(errors, OpValidationError{ 83 field: "AccountId", 84 reason: "embedded message failed validation", 85 cause: err, 86 }) 87 } 88 } 89 } else if v, ok := interface{}(m.GetAccountId()).(interface{ Validate() error }); ok { 90 if err := v.Validate(); err != nil { 91 return OpValidationError{ 92 field: "AccountId", 93 reason: "embedded message failed validation", 94 cause: err, 95 } 96 } 97 } 98 99 if all { 100 switch v := interface{}(m.GetPolicyId()).(type) { 101 case interface{ ValidateAll() error }: 102 if err := v.ValidateAll(); err != nil { 103 errors = append(errors, OpValidationError{ 104 field: "PolicyId", 105 reason: "embedded message failed validation", 106 cause: err, 107 }) 108 } 109 case interface{ Validate() error }: 110 if err := v.Validate(); err != nil { 111 errors = append(errors, OpValidationError{ 112 field: "PolicyId", 113 reason: "embedded message failed validation", 114 cause: err, 115 }) 116 } 117 } 118 } else if v, ok := interface{}(m.GetPolicyId()).(interface{ Validate() error }); ok { 119 if err := v.Validate(); err != nil { 120 return OpValidationError{ 121 field: "PolicyId", 122 reason: "embedded message failed validation", 123 cause: err, 124 } 125 } 126 } 127 128 // no validation rules for RelativeTo 129 130 if val := m.GetDelta(); val < -9007199254740 || val > 9007199254740 { 131 err := OpValidationError{ 132 field: "Delta", 133 reason: "value must be inside range [-9007199254740, 9007199254740]", 134 } 135 if !all { 136 return err 137 } 138 errors = append(errors, err) 139 } 140 141 // no validation rules for Options 142 143 if len(errors) > 0 { 144 return OpMultiError(errors) 145 } 146 147 return nil 148 } 149 150 // OpMultiError is an error wrapping multiple validation errors returned by 151 // Op.ValidateAll() if the designated constraints aren't met. 152 type OpMultiError []error 153 154 // Error returns a concatenation of all the error messages it wraps. 155 func (m OpMultiError) Error() string { 156 var msgs []string 157 for _, err := range m { 158 msgs = append(msgs, err.Error()) 159 } 160 return strings.Join(msgs, "; ") 161 } 162 163 // AllErrors returns a list of validation violation errors. 164 func (m OpMultiError) AllErrors() []error { return m } 165 166 // OpValidationError is the validation error returned by Op.Validate if the 167 // designated constraints aren't met. 168 type OpValidationError struct { 169 field string 170 reason string 171 cause error 172 key bool 173 } 174 175 // Field function returns field value. 176 func (e OpValidationError) Field() string { return e.field } 177 178 // Reason function returns reason value. 179 func (e OpValidationError) Reason() string { return e.reason } 180 181 // Cause function returns cause value. 182 func (e OpValidationError) Cause() error { return e.cause } 183 184 // Key function returns key value. 185 func (e OpValidationError) Key() bool { return e.key } 186 187 // ErrorName returns error name. 188 func (e OpValidationError) ErrorName() string { return "OpValidationError" } 189 190 // Error satisfies the builtin error interface 191 func (e OpValidationError) Error() string { 192 cause := "" 193 if e.cause != nil { 194 cause = fmt.Sprintf(" | caused by: %v", e.cause) 195 } 196 197 key := "" 198 if e.key { 199 key = "key for " 200 } 201 202 return fmt.Sprintf( 203 "invalid %sOp.%s: %s%s", 204 key, 205 e.field, 206 e.reason, 207 cause) 208 } 209 210 var _ error = OpValidationError{} 211 212 var _ interface { 213 Field() string 214 Reason() string 215 Key() bool 216 Cause() error 217 ErrorName() string 218 } = OpValidationError{}