Skip to content

Commit

Permalink
feat string operations
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jul 22, 2024
1 parent bdc339d commit f61a487
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions engine/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,55 +96,75 @@ func match(filter gjson.Result, data string, ids ...int64) (result bool, err err
switch sQueryKey.Str {

// compare sQueryKey
case "$gt":
if !(dataVal.Str > sQueryVal.Str) {

case "$st": // start with ..
if !strings.HasPrefix(dataVal.Str, sQueryVal.Str) {
result = false
}
return result

case "$lt":
if !(dataVal.Str < sQueryVal.Str) {
case "$en": // end with ..
if !strings.HasSuffix(dataVal.Str, sQueryVal.Str) {
result = false
}
return result

case "$gte":
if !(dataVal.Str >= sQueryVal.Str) {
case "$c": // contains ..
if !strings.Contains(dataVal.Str, sQueryVal.Str) {
result = false
}
return result

case "$lte":
if !(dataVal.Str <= sQueryVal.Str) {
case "$nst": // not start with ..
if strings.HasPrefix(dataVal.Str, sQueryVal.Str) {
result = false
}
return result

case "$eq":
if dataVal.Str != sQueryVal.Str {
case "$nen": // not end with ..
if strings.HasSuffix(dataVal.Str, sQueryVal.Str) {
result = false
}
return result

case "$nc": // not contains ..
if strings.Contains(dataVal.Str, sQueryVal.Str) {
result = false
}
return result

case "$ne":
if dataVal.Str == sQueryVal.Str {
result = false
}
return result

case "$st": // start with ..
if !strings.HasPrefix(dataVal.Str, sQueryVal.Str) {
case "$eq":
if dataVal.Str != sQueryVal.Str {
result = false
}
return result

case "$en": // end with ..
if !strings.HasSuffix(dataVal.Str, sQueryVal.Str) {
case "$gt":
if !(dataVal.Str > sQueryVal.Str) {
result = false
}
return result

case "$c": // contains ..
if !strings.Contains(dataVal.Str, sQueryVal.Str) {
case "$lt":
if !(dataVal.Str < sQueryVal.Str) {
result = false
}
return result

case "$gte":
if !(dataVal.Str >= sQueryVal.Str) {
result = false
}
return result

case "$lte":
if !(dataVal.Str <= sQueryVal.Str) {
result = false
}
return result
Expand Down

0 comments on commit f61a487

Please sign in to comment.