123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package zapx
- const (
- OrderAsc = "asc"
- OrderDesc = "desc"
- )
- const (
- OpLike = "like"
- OpIn = "in"
- OpNin = "nin"
- OpEq = "eq"
- OpNeq = "neq"
- OpGt = "gt"
- OpGte = "gte"
- OpLt = "lt"
- OpLte = "lte"
- )
- type StringFilter struct {
- Key string `json:"key"`
- Op string `json:"op"`
- Value string `json:"value"`
- }
- func (v StringFilter) Validate() error {
- if v.Key == "" {
- return ValidateError("扩展参数键不能为空")
- }
- if v.Op != OpEq && v.Op != OpNeq && v.Op != OpLike {
- return ValidateError("字符串型扩展参数操作符错误")
- }
- return nil
- }
- type FloatFilter struct {
- Key string `json:"key"`
- Op string `json:"op"`
- Value float64 `json:"value"`
- }
- func (v FloatFilter) Validate() error {
- if v.Key == "" {
- return ValidateError("扩展参数键不能为空")
- }
- if v.Op != OpEq && v.Op != OpNeq && v.Op != OpGt && v.Op != OpGte && v.Op != OpLt && v.Op != OpLte {
- return ValidateError("浮点数型扩展参数操作符错误")
- }
- return nil
- }
- type IntFilter struct {
- Key string `json:"key"`
- Op string `json:"op"`
- Value int32 `json:"value"`
- }
- func (v IntFilter) Validate() error {
- if v.Key == "" {
- return ValidateError("扩展参数键不能为空")
- }
- if v.Op != OpEq && v.Op != OpNeq && v.Op != OpGt && v.Op != OpGte && v.Op != OpLt && v.Op != OpLte {
- return ValidateError("整数型扩展参数操作符错误")
- }
- return nil
- }
- type BoolFilter struct {
- Key string `json:"key"`
- Op string `json:"op"`
- Value bool `json:"value"`
- }
- func (v BoolFilter) Validate() error {
- if v.Key == "" {
- return ValidateError("扩展参数键不能为空")
- }
- if v.Op != OpEq && v.Op != OpNeq {
- return ValidateError("布尔型扩展参数操作符错误")
- }
- return nil
- }
- type StringFieldFilter struct {
- Op string `json:"op"`
- Value string `json:"value"`
- }
- func (v StringFieldFilter) Validate() error {
- if v.Op != OpEq && v.Op != OpNeq && v.Op != OpLike {
- return ValidateError("参数操作符错误")
- }
- return nil
- }
- type StringInFieldFilter struct {
- Op string `json:"op"`
- Value []string `json:"value"`
- }
- func (v StringInFieldFilter) Validate() error {
- if v.Op != OpIn && v.Op != OpNin {
- return ValidateError("参数操作符错误")
- }
- return nil
- }
|