Skip to content

Commit

Permalink
fix uncomapred int
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jul 9, 2024
1 parent 2b43666 commit ac9a381
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
47 changes: 24 additions & 23 deletions engine/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,40 @@ func match(filter gjson.Result, data string) (result bool, err error) {
if subQueryVal.Type == 3 { // 3:string,
//fmt.Println("here with: ", subQueryKey.String())

switch subQueryKey.String() {
switch subQueryKey.Str { // .String()

// comparition
case "$gt":
if !(dataVal.String() > subQueryVal.String()) {
if !(dataVal.Str > subQueryVal.Str) {
result = false
}
return result

case "$lt":
if !(dataVal.String() < subQueryVal.String()) {
if !(dataVal.Str < subQueryVal.Str) {
result = false
}
return result

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

case "$lte":
if !(dataVal.String() <= subQueryVal.String()) {
if !(dataVal.Str <= subQueryVal.Str) {
result = false
}
return result

case "$eq":
if dataVal.String() != subQueryVal.String() {
if dataVal.Str != subQueryVal.Str {
result = false
}
return result
case "$ne":
if dataVal.String() == subQueryVal.String() {
if dataVal.Str == subQueryVal.Str {
result = false
}
return result
Expand All @@ -71,19 +71,19 @@ func match(filter gjson.Result, data string) (result bool, err error) {
return result

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

case "$en": // is it end with
if !strings.HasSuffix(dataVal.String(), subQueryVal.String()) {
if !strings.HasSuffix(dataVal.Str, subQueryVal.Str) {
result = false
}
return result

case "$c": // is it contains
if !strings.Contains(dataVal.String(), subQueryVal.String()) {
if !strings.Contains(dataVal.Str, subQueryVal.Str) {
result = false
}
return result
Expand All @@ -94,49 +94,48 @@ func match(filter gjson.Result, data string) (result bool, err error) {
result = false
return result
}

}

switch subQueryKey.String() {
switch subQueryKey.Str {
case "$gt":
if !(dataVal.Int() > subQueryVal.Int()) {
if !(dataVal.Num > subQueryVal.Num) {
result = false
}
return result

case "$lt":
if !(dataVal.Int() < subQueryVal.Int()) {
if !(dataVal.Num < subQueryVal.Num) {
result = false
}
return result

case "$gte":
if !(dataVal.Int() >= subQueryVal.Int()) {
if !(dataVal.Num >= subQueryVal.Num) {
result = false
}
return result

case "$lte":
if !(dataVal.Int() <= subQueryVal.Int()) {
if !(dataVal.Num <= subQueryVal.Num) {
result = false
}
return result

case "$eq":
if dataVal.Int() != subQueryVal.Int() {
if dataVal.Num != subQueryVal.Num {
result = false
}
return result

case "$ne":
if dataVal.Int() == subQueryVal.Int() {
if dataVal.Num == subQueryVal.Num {
result = false
}
return result

case "$in": // in array
for _, v := range subQueryVal.Array() {
if dataVal.String() == v.String() {
if dataVal.Str == v.Str {
return result
}
}
Expand All @@ -145,7 +144,7 @@ func match(filter gjson.Result, data string) (result bool, err error) {

case "$nin": // not in
for _, v := range subQueryVal.Array() {
if dataVal.String() == v.String() {
if dataVal.Str == v.Str {
result = false
return result
}
Expand Down Expand Up @@ -188,20 +187,22 @@ func match(filter gjson.Result, data string) (result bool, err error) {
return result
}

err = fmt.Errorf("unknown %s operation", subQueryKey.String())
err = fmt.Errorf("unknown %s operation", subQueryKey.Str)
result = false
return result
}
})

match(queryVal, queryVal.String())
match(queryVal, queryVal.Str)
return result
}

if dataVal.String() != queryVal.String() {
if dataVal.Str != queryVal.Str {
result = false
}
return result // if true keep iterating
})
return result, err
}

// end
4 changes: 2 additions & 2 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
* {
font-size: 1.05em; /* Ems */
font-size: 1.02em; /* Ems */
}

body {
Expand All @@ -17,7 +17,7 @@ body {
height: calc(100vh - 100px);
flex-direction: column;
overflow: auto;
font-size: 1.2em;
/*font-size: 1.2em;*/
}

#data {
Expand Down

0 comments on commit ac9a381

Please sign in to comment.