[feat] 新增 New Option 可选项
This commit is contained in:
+24
-2
@@ -213,6 +213,28 @@ func (this Condition) GetFields(operator ConditionOperator, types ...ConditionTo
|
||||
return result
|
||||
}
|
||||
|
||||
func New(typ ConditionType, describe string) *Condition {
|
||||
return &Condition{typ: typ, describe: describe}
|
||||
type Option func(option *Condition)
|
||||
|
||||
func Type(v ConditionType) Option {
|
||||
return func(option *Condition) {
|
||||
option.typ = v
|
||||
}
|
||||
}
|
||||
|
||||
func Describe(v string) Option {
|
||||
return func(option *Condition) {
|
||||
option.describe = v
|
||||
}
|
||||
}
|
||||
|
||||
func New(opts ...Option) *Condition {
|
||||
cond := &Condition{typ: AND}
|
||||
|
||||
if l := len(opts); l > 0 {
|
||||
for i := 0; i < l; i++ {
|
||||
opts[i](cond)
|
||||
}
|
||||
}
|
||||
|
||||
return cond
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user