forked from tidepool-org/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.go
138 lines (105 loc) · 3.08 KB
/
validator.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package structure
import (
"regexp"
"time"
)
type Validatable interface {
Validate(validator Validator)
}
type Validator interface {
Error() error
Validate(validatable Validatable) error
Validating(reference string, validatable Validatable) Validating
Bool(reference string, value *bool) Bool
Float64(reference string, value *float64) Float64
Int(reference string, value *int) Int
String(reference string, value *string) String
StringArray(reference string, value *[]string) StringArray
Time(reference string, value *time.Time) Time
WithSource(source Source) Validator
WithMeta(meta interface{}) Validator
WithReference(reference string) Validator
}
type Validating interface {
Exists() Validating
NotExists() Validating
Validate() Validating
}
type Bool interface {
Exists() Bool
NotExists() Bool
True() Bool
False() Bool
}
type Float64 interface {
Exists() Float64
NotExists() Float64
EqualTo(value float64) Float64
NotEqualTo(value float64) Float64
LessThan(limit float64) Float64
LessThanOrEqualTo(limit float64) Float64
GreaterThan(limit float64) Float64
GreaterThanOrEqualTo(limit float64) Float64
InRange(lowerLimit float64, upperLimit float64) Float64
OneOf(allowedValues ...float64) Float64
NotOneOf(disallowedValues ...float64) Float64
}
type Int interface {
Exists() Int
NotExists() Int
EqualTo(value int) Int
NotEqualTo(value int) Int
LessThan(limit int) Int
LessThanOrEqualTo(limit int) Int
GreaterThan(limit int) Int
GreaterThanOrEqualTo(limit int) Int
InRange(lowerLimit int, upperLimit int) Int
OneOf(allowedValues ...int) Int
NotOneOf(disallowedValues ...int) Int
}
type String interface {
Exists() String
NotExists() String
Empty() String
NotEmpty() String
EqualTo(value string) String
NotEqualTo(value string) String
LengthEqualTo(limit int) String
LengthNotEqualTo(limit int) String
LengthLessThan(limit int) String
LengthLessThanOrEqualTo(limit int) String
LengthGreaterThan(limit int) String
LengthGreaterThanOrEqualTo(limit int) String
LengthInRange(lowerLimit int, upperLimit int) String
OneOf(allowedValues ...string) String
NotOneOf(disallowedValues ...string) String
Matches(expression *regexp.Regexp) String
NotMatches(expression *regexp.Regexp) String
}
type StringArray interface {
Exists() StringArray
NotExists() StringArray
Empty() StringArray
NotEmpty() StringArray
LengthEqualTo(limit int) StringArray
LengthNotEqualTo(limit int) StringArray
LengthLessThan(limit int) StringArray
LengthLessThanOrEqualTo(limit int) StringArray
LengthGreaterThan(limit int) StringArray
LengthGreaterThanOrEqualTo(limit int) StringArray
LengthInRange(lowerLimit int, upperLimit int) StringArray
EachOneOf(allowedValues ...string) StringArray
EachNotOneOf(disallowedValues ...string) StringArray
EachMatches(expression *regexp.Regexp) StringArray
EachNotMatches(expression *regexp.Regexp) StringArray
}
type Time interface {
Exists() Time
NotExists() Time
Zero() Time
NotZero() Time
After(limit time.Time) Time
AfterNow(threshold time.Duration) Time
Before(limit time.Time) Time
BeforeNow(threshold time.Duration) Time
}