-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_options.go
50 lines (42 loc) · 998 Bytes
/
record_options.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
package v1
type RecordOption struct {
Prefix string
IsNested bool
Nulled bool
}
type RecordOptionsFunc func(option *RecordOption)
func RecordOptionPrefix(prefix string) RecordOptionsFunc {
return func(option *RecordOption) {
option.Prefix = prefix
}
}
func RecordOptionIsNested(b bool) RecordOptionsFunc {
return func(option *RecordOption) {
option.IsNested = b
}
}
func RecordOptionNulled(b bool) RecordOptionsFunc {
return func(option *RecordOption) {
option.Nulled = b
}
}
func NewRecordOptions(opts []RecordOptionsFunc) *RecordOption {
option := &RecordOption{}
for _, opt := range opts {
opt(option)
}
if option.Prefix == "" {
option.Prefix = columnPrefix
}
return option
}
func (r *RecordOption) ColumnName(in string) string {
return r.Prefix + in
}
func (r *RecordOption) Nested(prefix string) []RecordOptionsFunc {
return []RecordOptionsFunc{
RecordOptionPrefix(r.Prefix + prefix),
RecordOptionIsNested(true),
RecordOptionNulled(r.Nulled),
}
}