-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidator_int.go
More file actions
60 lines (51 loc) · 1.45 KB
/
Copy pathvalidator_int.go
File metadata and controls
60 lines (51 loc) · 1.45 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
package validator
import "fmt"
// IsInt64Between returns true if value lies between min and max (inclusive)
func IsInt64Between(value, min, max int64) bool {
if min > max {
min, max = max, min
}
return value >= min && value <= max
}
// IsInt64Gt returns true if value is greater than threshold
func IsInt64Gt(value, threshold int64) bool {
return value > threshold
}
// IsInt64Gte returns true if value is greater than or equal to threshold
func IsInt64Gte(value, threshold int64) bool {
return value >= threshold
}
// IsInt64Lt returns true if value is less than threshold
func IsInt64Lt(value, threshold int64) bool {
return value < threshold
}
// IsInt64Lte returns true if value is less than or equal to threshold
func IsInt64Lte(value, threshold int64) bool {
return value <= threshold
}
// Aliases for consistency with other validators.
var (
IsInt64Min = IsInt64Gte
IsInt64Max = IsInt64Lte
)
// Deprecated: Use Is* functions instead.
var (
ValidateDigitsBetweenInt64 = IsInt64Between
)
// compareInt64 determine if a comparison passes between the given values.
func compareInt64(first, second int64, 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: compareInt64 unsupported operator %s", operator)
}
}