-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidator_float.go
More file actions
66 lines (57 loc) · 1.77 KB
/
Copy pathvalidator_float.go
File metadata and controls
66 lines (57 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package validator
import "fmt"
// IsFloat64Between returns true if value lies between min and max (inclusive)
func IsFloat64Between(value, min, max float64) bool {
if min > max {
min, max = max, min
}
return value >= min && value <= max
}
// IsFloat64Gt returns true if value is greater than threshold
func IsFloat64Gt(value, threshold float64) bool {
return value > threshold
}
// IsFloat64Gte returns true if value is greater than or equal to threshold
func IsFloat64Gte(value, threshold float64) bool {
return value >= threshold
}
// IsFloat64Lt returns true if value is less than threshold
func IsFloat64Lt(value, threshold float64) bool {
return value < threshold
}
// IsFloat64Lte returns true if value is less than or equal to threshold
func IsFloat64Lte(value, threshold float64) bool {
return value <= threshold
}
// Aliases for consistency with other validators.
var (
IsFloat64Min = IsFloat64Gte
IsFloat64Max = IsFloat64Lte
)
// Deprecated: Use Is* functions instead.
var (
ValidateDigitsBetweenFloat64 = IsFloat64Between
ValidateMaxFloat64 = IsFloat64Lte
ValidateMinFloat64 = IsFloat64Gte
ValidateLtFloat64 = IsFloat64Lt
ValidateLteFloat64 = IsFloat64Lte
ValidateGteFloat64 = IsFloat64Gte
ValidateGtFloat64 = IsFloat64Gt
)
// compareFloat64 determines if a comparison passes between the given values.
func compareFloat64(first, second float64, operator string) (bool, error) {
switch operator {
case "<":
return first < second, nil
case ">":
return first > second, nil
case "<=":
return first <= second, nil
case ">=":
return first >= second, nil
case "==":
return first == second, nil
default:
return false, fmt.Errorf("validator: compareFloat64 unsupported operator %s", operator)
}
}