-
Notifications
You must be signed in to change notification settings - Fork 1
/
field_builder.go
45 lines (38 loc) · 984 Bytes
/
field_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
45
package nero
import "github.com/stevenferrer/mira"
// FieldBuilder is a field builder
type FieldBuilder struct {
f *Field
}
// NewFieldBuilder takes a field name and a value and returns a FieldBuilder
func NewFieldBuilder(name string, v interface{}) *FieldBuilder {
return &FieldBuilder{&Field{
name: name,
typeInfo: mira.NewTypeInfo(v),
}}
}
// Auto sets the auto-populated flag
func (fb *FieldBuilder) Auto() *FieldBuilder {
fb.f.auto = true
return fb
}
// Optional sets the optional flag
func (fb *FieldBuilder) Optional() *FieldBuilder {
fb.f.optional = true
return fb
}
// StructField sets the struct field
func (fb *FieldBuilder) StructField(structField string) *FieldBuilder {
fb.f.structField = structField
return fb
}
// Build builds the field
func (fb *FieldBuilder) Build() *Field {
return &Field{
name: fb.f.name,
typeInfo: fb.f.typeInfo,
auto: fb.f.auto,
optional: fb.f.optional,
structField: fb.f.structField,
}
}