validateSingleHardLimit validates a single limit against its hard limit
(limitName string, value, hardLimit any)
| 94 | |
| 95 | // validateSingleHardLimit validates a single limit against its hard limit |
| 96 | func (a *API) validateSingleHardLimit(limitName string, value, hardLimit any) error { |
| 97 | // Convert both values to float64 for comparison |
| 98 | valueFloat, err := convertToFloat64(value) |
| 99 | if err != nil { |
| 100 | return nil // Skip validation for unparseable values |
| 101 | } |
| 102 | |
| 103 | hardLimitFloat, err := convertToFloat64(hardLimit) |
| 104 | if err != nil { |
| 105 | return nil // Skip validation for unparseable hard limits |
| 106 | } |
| 107 | |
| 108 | // Hard limit is inclusive - values equal to the hard limit are allowed |
| 109 | // For example, if hard limit is 100000, then 100000 is allowed but 100001 is not |
| 110 | if valueFloat > hardLimitFloat { |
| 111 | return fmt.Errorf("limit %s exceeds hard limit: %f > %f", limitName, valueFloat, hardLimitFloat) |
| 112 | } |
| 113 | |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | // convertToFloat64 converts any value to float64 |
| 118 | func convertToFloat64(v any) (float64, error) { |
no test coverage detected