forked from tidepool-org/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.go
77 lines (60 loc) · 1.95 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
package validator
import (
"time"
"github.com/tidepool-org/platform/structure"
structureBase "github.com/tidepool-org/platform/structure/base"
)
type Validator struct {
base *structureBase.Base
}
func New() *Validator {
return NewValidator(structureBase.New().WithSource(structure.NewPointerSource()))
}
func NewValidator(base *structureBase.Base) *Validator {
return &Validator{
base: base,
}
}
func (v *Validator) Error() error {
return v.base.Error()
}
func (v *Validator) Validate(validatable structure.Validatable) error {
validatable.Validate(v)
return v.Error()
}
func (v *Validator) Validating(reference string, value structure.Validatable) structure.Validating {
return NewValidating(v.base.WithReference(reference), value)
}
func (v *Validator) Bool(reference string, value *bool) structure.Bool {
return NewBool(v.base.WithReference(reference), value)
}
func (v *Validator) Float64(reference string, value *float64) structure.Float64 {
return NewFloat64(v.base.WithReference(reference), value)
}
func (v *Validator) Int(reference string, value *int) structure.Int {
return NewInt(v.base.WithReference(reference), value)
}
func (v *Validator) String(reference string, value *string) structure.String {
return NewString(v.base.WithReference(reference), value)
}
func (v *Validator) StringArray(reference string, value *[]string) structure.StringArray {
return NewStringArray(v.base.WithReference(reference), value)
}
func (v *Validator) Time(reference string, value *time.Time) structure.Time {
return NewTime(v.base.WithReference(reference), value)
}
func (v *Validator) WithSource(source structure.Source) structure.Validator {
return &Validator{
base: v.base.WithSource(source),
}
}
func (v *Validator) WithMeta(meta interface{}) structure.Validator {
return &Validator{
base: v.base.WithMeta(meta),
}
}
func (v *Validator) WithReference(reference string) structure.Validator {
return &Validator{
base: v.base.WithReference(reference),
}
}