forked from tidepool-org/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
float64.go
119 lines (105 loc) · 2.55 KB
/
float64.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
package validator
import (
"github.com/tidepool-org/platform/structure"
structureBase "github.com/tidepool-org/platform/structure/base"
)
type Float64 struct {
base *structureBase.Base
value *float64
}
func NewFloat64(base *structureBase.Base, value *float64) *Float64 {
return &Float64{
base: base,
value: value,
}
}
func (f *Float64) Exists() structure.Float64 {
if f.value == nil {
f.base.ReportError(ErrorValueNotExists())
}
return f
}
func (f *Float64) NotExists() structure.Float64 {
if f.value != nil {
f.base.ReportError(ErrorValueExists())
}
return f
}
func (f *Float64) EqualTo(value float64) structure.Float64 {
if f.value != nil {
if *f.value != value {
f.base.ReportError(ErrorValueNotEqualTo(*f.value, value))
}
}
return f
}
func (f *Float64) NotEqualTo(value float64) structure.Float64 {
if f.value != nil {
if *f.value == value {
f.base.ReportError(ErrorValueEqualTo(*f.value, value))
}
}
return f
}
func (f *Float64) LessThan(limit float64) structure.Float64 {
if f.value != nil {
if *f.value >= limit {
f.base.ReportError(ErrorValueNotLessThan(*f.value, limit))
}
}
return f
}
func (f *Float64) LessThanOrEqualTo(limit float64) structure.Float64 {
if f.value != nil {
if *f.value > limit {
f.base.ReportError(ErrorValueNotLessThanOrEqualTo(*f.value, limit))
}
}
return f
}
func (f *Float64) GreaterThan(limit float64) structure.Float64 {
if f.value != nil {
if *f.value <= limit {
f.base.ReportError(ErrorValueNotGreaterThan(*f.value, limit))
}
}
return f
}
func (f *Float64) GreaterThanOrEqualTo(limit float64) structure.Float64 {
if f.value != nil {
if *f.value < limit {
f.base.ReportError(ErrorValueNotGreaterThanOrEqualTo(*f.value, limit))
}
}
return f
}
func (f *Float64) InRange(lowerLimit float64, upperLimit float64) structure.Float64 {
if f.value != nil {
if *f.value < lowerLimit || *f.value > upperLimit {
f.base.ReportError(ErrorValueNotInRange(*f.value, lowerLimit, upperLimit))
}
}
return f
}
func (f *Float64) OneOf(allowedValues ...float64) structure.Float64 {
if f.value != nil {
for _, allowedValue := range allowedValues {
if allowedValue == *f.value {
return f
}
}
f.base.ReportError(ErrorValueFloat64NotOneOf(*f.value, allowedValues))
}
return f
}
func (f *Float64) NotOneOf(disallowedValues ...float64) structure.Float64 {
if f.value != nil {
for _, disallowedValue := range disallowedValues {
if disallowedValue == *f.value {
f.base.ReportError(ErrorValueFloat64OneOf(*f.value, disallowedValues))
return f
}
}
}
return f
}