conditions.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package rest
  2. type ConditionOperator string
  3. const (
  4. OperatorEqual = "="
  5. OperatorNotEqual = "!="
  6. OperatorMore = ">"
  7. OperatorLess = "<"
  8. OperatorMoreEqual = ">="
  9. OperatorLessEqual = "<="
  10. OperatorLike = "like"
  11. )
  12. func (s ConditionOperator) IsValid() bool {
  13. switch s {
  14. case OperatorEqual:
  15. case OperatorNotEqual:
  16. case OperatorMore:
  17. case OperatorLess:
  18. case OperatorMoreEqual:
  19. case OperatorLessEqual:
  20. case OperatorLike:
  21. default:
  22. return false
  23. }
  24. return true
  25. }
  26. //////////////////////////////////////////////////////////////////////////////
  27. const (
  28. LogicEmpty = ""
  29. LogicOR = "or"
  30. LogicAND = "and"
  31. )
  32. type ConditionLogic string
  33. func (s ConditionLogic) IsValid() bool {
  34. switch s {
  35. case LogicEmpty:
  36. case LogicOR:
  37. case LogicAND:
  38. default:
  39. return false
  40. }
  41. return true
  42. }
  43. //////////////////////////////////////////////////////////////////////////////
  44. type Condition struct {
  45. Field string
  46. Logic ConditionLogic
  47. Operator ConditionOperator
  48. Value any
  49. }
  50. func (s *Condition) IsValid() bool {
  51. return len(s.Field) > 0 && s.Logic.IsValid() && s.Operator.IsValid()
  52. }