-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoption.go
62 lines (50 loc) · 1020 Bytes
/
option.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
package mapper
/***************************
@author: tiansheng.ren
@date: 2022/11/1
@desc:
***************************/
type Option struct {
copyPrivate *bool
validateStruct *bool
}
var (
optionTrue = true
optionFalse = false
)
func mergeOption(options ...Option) Option {
ro := DefaultOption()
for _, option := range options {
if option.validateStruct != nil {
ro.validateStruct = option.validateStruct
}
if option.copyPrivate != nil {
ro.copyPrivate = option.copyPrivate
}
}
return ro
}
func DefaultOption() Option {
return Option{
copyPrivate: &optionFalse,
validateStruct: &optionFalse,
}
}
func (o Option) CopyPrivate() Option {
o.copyPrivate = &optionTrue
return o
}
func (o Option) ValidateStruct() Option {
o.validateStruct = &optionTrue
return o
}
func OptionCopyPrivate() Option {
o := DefaultOption()
o.copyPrivate = &optionTrue
return o
}
func OptionValidateStruct() Option {
o := DefaultOption()
o.validateStruct = &optionTrue
return o
}