-
Notifications
You must be signed in to change notification settings - Fork 1
/
builder.go
44 lines (37 loc) · 947 Bytes
/
builder.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
package forms
type FieldBuilder struct {
formatters []FormatterFunc
loader LoaderFunc
validators []ValidatorFunc
required bool
empty interface{}
}
func (fb *FieldBuilder) WithFormatters(formatters ...FormatterFunc) *FieldBuilder {
fb.formatters = append(fb.formatters, formatters...)
return fb
}
func (fb *FieldBuilder) WithValidators(validators ...ValidatorFunc) *FieldBuilder {
fb.validators = append(fb.validators, validators...)
return fb
}
func (fb *FieldBuilder) Loader(loader LoaderFunc) *FieldBuilder {
fb.loader = loader
return fb
}
func (fb *FieldBuilder) Required() *FieldBuilder {
fb.required = true
return fb
}
func (fb *FieldBuilder) Empty(value interface{}) *FieldBuilder {
fb.empty = value
return fb
}
func (fb *FieldBuilder) Build() *Field {
return &Field{
formatters: fb.formatters,
loader: fb.loader,
validators: fb.validators,
required: fb.required,
empty: fb.empty,
}
}