| 599 | } |
| 600 | |
| 601 | func validatorIntConfig(val *env.Validator, configKey string) (int, error) { |
| 602 | if limit, found := val.ConfigValue(configKey); found { |
| 603 | // In case of protos, config value is of type google.protobuf.Value, which numeric values are always a double. |
| 604 | if v, isDouble := limit.(float64); isDouble { |
| 605 | if v != float64(int64(v)) { |
| 606 | return 0, fmt.Errorf("invalid validator: %s, %s value is not a whole number: %v", val.Name, configKey, limit) |
| 607 | } |
| 608 | return int(v), nil |
| 609 | } |
| 610 | |
| 611 | if v, isInt := limit.(int); isInt { |
| 612 | return v, nil |
| 613 | } |
| 614 | return 0, fmt.Errorf("invalid validator: %s unsupported %s type: %v", val.Name, configKey, limit) |
| 615 | } |
| 616 | return 0, fmt.Errorf("invalid validator: %s missing %s", val.Name, configKey) |
| 617 | } |