Skip to content

Commit

Permalink
feat simple match
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jul 15, 2024
1 parent c7dd0ac commit c2cea5f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions engine/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func match(filter gjson.Result, data string) (result bool, err error) {

filter.ForEach(func(queryKey, queryVal gjson.Result) bool {

dataVal := gjson.Get(data, queryKey.String())
dataVal := gjson.Get(data, queryKey.Str)

if queryVal.Type == 5 { // 5:json, int:2, string:3
if queryVal.Type == 5 { // 5:json-array, 2:int, 3:string
queryVal.ForEach(func(subQueryKey, subQueryVal gjson.Result) bool {

if subQueryVal.Type == 3 { // 3:string,
Expand Down Expand Up @@ -265,10 +265,20 @@ func match(filter gjson.Result, data string) (result bool, err error) {
return result
}

if dataVal.Str != queryVal.Str {
// when value of query is number {age: 10}
if queryVal.Type == 2 {
if queryVal.Num != dataVal.Num {
result = false
}
}

// when value of query is string : {name: "adam"}
if queryVal.Str != dataVal.Str {
result = false
}
return result // if true keep iterating

// if result is true then keep iterating
return result
})
return result, err
}
Expand Down

0 comments on commit c2cea5f

Please sign in to comment.