package zapx // 排序方式 const ( OrderAsc = "asc" OrderDesc = "desc" ) // 操作符 const ( OpLike = "like" // like %s% OpIn = "in" // in OpNin = "nin" // not in OpEq = "eq" // = OpNeq = "neq" // <> OpGt = "gt" // > OpGte = "gte" // >= OpLt = "lt" // < OpLte = "lte" // <= ) // StringFilter 字符串类型的扩展参数 type StringFilter struct { Key string `json:"key"` // 键。必填。 Op string `json:"op"` // 操作符。必填。 Value string `json:"value"` // 值。必填。但可以为空。 } // Validate 校验参数 func (v StringFilter) Validate() error { if v.Key == "" { return ValidateError("扩展参数键不能为空") } if v.Op != OpEq && v.Op != OpNeq && v.Op != OpLike { return ValidateError("字符串型扩展参数操作符错误") } return nil } // FloatFilter 浮点数类型的扩展参数 type FloatFilter struct { Key string `json:"key"` // 键。必填。 Op string `json:"op"` // 操作符。必填。 Value float64 `json:"value"` // 值。必填。 } // Validate 校验参数 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 } // IntFilter 整数类型的扩展参数 type IntFilter struct { Key string `json:"key"` // 键。必填。 Op string `json:"op"` // 操作符。必填。 Value int32 `json:"value"` // 值。必填。 } // Validate 校验参数 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 } // BoolFilter 布尔类型的扩展参数 type BoolFilter struct { Key string `json:"key"` // 键。必填。 Op string `json:"op"` // 操作符。必填。 Value bool `json:"value"` // 值。必填。 } // Validate 校验参数 func (v BoolFilter) Validate() error { if v.Key == "" { return ValidateError("扩展参数键不能为空") } if v.Op != OpEq && v.Op != OpNeq { return ValidateError("布尔型扩展参数操作符错误") } return nil } // StringFieldFilter 字段过滤条件,适用于指定了字段的情况。 type StringFieldFilter struct { Op string `json:"op"` // 操作符 Value string `json:"value"` // 参数。必填但可为空串。 } // Validate 校验参数 func (v StringFieldFilter) Validate() error { if v.Op != OpEq && v.Op != OpNeq && v.Op != OpLike { return ValidateError("参数操作符错误") } return nil } // StringInFieldFilter 字段过滤条件,适用于指定了字段的情况。 type StringInFieldFilter struct { Op string `json:"op"` // 操作符 Value []string `json:"value"` // 参数 } // Validate 校验参数 func (v StringInFieldFilter) Validate() error { if v.Op != OpIn && v.Op != OpNin { return ValidateError("参数操作符错误") } return nil }