|
@@ -6,23 +6,23 @@ import (
|
|
"git.ali33.ru/fcg-xvii/go-tools/json"
|
|
"git.ali33.ru/fcg-xvii/go-tools/json"
|
|
)
|
|
)
|
|
|
|
|
|
-func parseCondition(m json.Map, index int) (ICondition, error) {
|
|
|
|
|
|
+func parseCondition(m json.Map, index int) (*Condition, error) {
|
|
errPrefix := func(errData string) error {
|
|
errPrefix := func(errData string) error {
|
|
return fmt.Errorf("[%v]: %s", index, errData)
|
|
return fmt.Errorf("[%v]: %s", index, errData)
|
|
}
|
|
}
|
|
- cond := _condition{
|
|
|
|
- field: m.String("field", ""),
|
|
|
|
- logic: ConditionLogic(m.String("logic", "")),
|
|
|
|
- operator: ConditionOperator(m.String("operator", "")),
|
|
|
|
- value: m["value"],
|
|
|
|
|
|
+ cond := Condition{
|
|
|
|
+ Field: m.String("field", ""),
|
|
|
|
+ Logic: ConditionLogic(m.String("logic", "")),
|
|
|
|
+ Operator: ConditionOperator(m.String("operator", "")),
|
|
|
|
+ Value: m["value"],
|
|
}
|
|
}
|
|
if !cond.IsValid() {
|
|
if !cond.IsValid() {
|
|
- if len(cond.field) == 0 {
|
|
|
|
|
|
+ if len(cond.Field) == 0 {
|
|
return nil, errPrefix("empty field name")
|
|
return nil, errPrefix("empty field name")
|
|
- } else if !cond.operator.IsValid() {
|
|
|
|
- return nil, errPrefix(fmt.Sprintf("unexpected operator [%s]", cond.operator))
|
|
|
|
- } else if !cond.operator.IsValid() {
|
|
|
|
- return nil, errPrefix(fmt.Sprintf("unexpected logic [%s]", cond.logic))
|
|
|
|
|
|
+ } else if !cond.Operator.IsValid() {
|
|
|
|
+ return nil, errPrefix(fmt.Sprintf("unexpected operator [%s]", cond.Operator))
|
|
|
|
+ } else if !cond.Operator.IsValid() {
|
|
|
|
+ return nil, errPrefix(fmt.Sprintf("unexpected logic [%s]", cond.Logic))
|
|
} else {
|
|
} else {
|
|
return nil, errPrefix("unexpected error")
|
|
return nil, errPrefix("unexpected error")
|
|
}
|
|
}
|
|
@@ -32,15 +32,6 @@ func parseCondition(m json.Map, index int) (ICondition, error) {
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-type ICondition interface {
|
|
|
|
- Field() string
|
|
|
|
- Logic() ConditionLogic
|
|
|
|
- Operator() ConditionOperator
|
|
|
|
- Value() any
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//////////////////////////////////////////////////////////////////////////////
|
|
|
|
-
|
|
|
|
type ConditionOperator string
|
|
type ConditionOperator string
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -91,29 +82,13 @@ func (s ConditionLogic) IsValid() bool {
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-type _condition struct {
|
|
|
|
- field string
|
|
|
|
- logic ConditionLogic
|
|
|
|
- operator ConditionOperator
|
|
|
|
- value any
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (s *_condition) Field() string {
|
|
|
|
- return s.field
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (s *_condition) Logic() ConditionLogic {
|
|
|
|
- return s.logic
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (s *_condition) Operator() ConditionOperator {
|
|
|
|
- return s.operator
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (s *_condition) Value() any {
|
|
|
|
- return s.value
|
|
|
|
|
|
+type Condition struct {
|
|
|
|
+ Field string
|
|
|
|
+ Logic ConditionLogic
|
|
|
|
+ Operator ConditionOperator
|
|
|
|
+ Value any
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *_condition) IsValid() bool {
|
|
|
|
- return len(s.field) > 0 && s.logic.IsValid() && s.operator.IsValid()
|
|
|
|
|
|
+func (s *Condition) IsValid() bool {
|
|
|
|
+ return len(s.Field) > 0 && s.Logic.IsValid() && s.Operator.IsValid()
|
|
}
|
|
}
|