[feat] 新增 New Option 可选项

This commit is contained in:
2024-05-09 10:08:28 +08:00
parent e54629237c
commit 8270326a7b
4 changed files with 92 additions and 41 deletions
+24 -2
View File
@@ -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
}