-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidator_unit.go
More file actions
60 lines (51 loc) · 1.48 KB
/
Copy pathvalidator_unit.go
File metadata and controls
60 lines (51 loc) · 1.48 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"
// IsUint64Between returns true if value lies between min and max (inclusive)
func IsUint64Between(value, min, max uint64) bool {
if min > max {
min, max = max, min
}
return value >= min && value <= max
}
// IsUint64Gt returns true if value is greater than threshold
func IsUint64Gt(value, threshold uint64) bool {
return value > threshold
}
// IsUint64Gte returns true if value is greater than or equal to threshold
func IsUint64Gte(value, threshold uint64) bool {
return value >= threshold
}
// IsUint64Lt returns true if value is less than threshold
func IsUint64Lt(value, threshold uint64) bool {
return value < threshold
}
// IsUint64Lte returns true if value is less than or equal to threshold
func IsUint64Lte(value, threshold uint64) bool {
return value <= threshold
}
// Aliases for consistency with other validators.
var (
IsUint64Min = IsUint64Gte
IsUint64Max = IsUint64Lte
)
// Deprecated: Use Is* functions instead.
var (
ValidateDigitsBetweenUint64 = IsUint64Between
)
// compareUint64 determine if a comparison passes between the given values.
func compareUint64(first, second uint64, 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: compareUint64 unsupported operator %s", operator)
}
}