MCPcopy Index your code
hub / github.com/cortexlabs/cortex / ValidateIntVal

Function ValidateIntVal

pkg/lib/configreader/int.go:188–223  ·  view source on GitHub ↗
(val int, v *IntValidation)

Source from the content-addressed store, hash-verified

186}
187
188func ValidateIntVal(val int, v *IntValidation) error {
189 if v.GreaterThan != nil {
190 if val <= *v.GreaterThan {
191 return ErrorMustBeGreaterThan(val, *v.GreaterThan)
192 }
193 }
194 if v.GreaterThanOrEqualTo != nil {
195 if val < *v.GreaterThanOrEqualTo {
196 return ErrorMustBeGreaterThanOrEqualTo(val, *v.GreaterThanOrEqualTo)
197 }
198 }
199 if v.LessThan != nil {
200 if val >= *v.LessThan {
201 return ErrorMustBeLessThan(val, *v.LessThan)
202 }
203 }
204 if v.LessThanOrEqualTo != nil {
205 if val > *v.LessThanOrEqualTo {
206 return ErrorMustBeLessThanOrEqualTo(val, *v.LessThanOrEqualTo)
207 }
208 }
209
210 if len(v.AllowedValues) > 0 {
211 if !slices.HasInt(append(v.AllowedValues, v.HiddenAllowedValues...), val) {
212 return ErrorInvalidInt(val, v.AllowedValues[0], v.AllowedValues[1:]...)
213 }
214 }
215
216 if len(v.DisallowedValues) > 0 {
217 if slices.HasInt(v.DisallowedValues, val) {
218 return ErrorDisallowedValue(val)
219 }
220 }
221
222 return nil
223}
224
225//
226// Musts

Callers 2

validateIntFunction · 0.85
validateIntPtrFunction · 0.85

Calls 7

HasIntFunction · 0.92
ErrorMustBeGreaterThanFunction · 0.85
ErrorMustBeLessThanFunction · 0.85
ErrorInvalidIntFunction · 0.85
ErrorDisallowedValueFunction · 0.85

Tested by

no test coverage detected