Skip to content

Commit 54ed9bc

Browse files
committed
query: make compare by value work for all comparisons
1 parent 74196ce commit 54ed9bc

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

query/filter.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,22 @@ type FilterValueCompare struct {
3838
}
3939

4040
func (f FilterValueCompare) Filter(e Entry) bool {
41+
cmp := bytes.Compare(e.Value, f.Value)
4142
switch f.Op {
4243
case Equal:
43-
return bytes.Equal(f.Value, e.Value)
44+
return cmp == 0
4445
case NotEqual:
45-
return !bytes.Equal(f.Value, e.Value)
46+
return cmp != 0
47+
case LessThan:
48+
return cmp < 0
49+
case LessThanOrEqual:
50+
return cmp <= 0
51+
case GreaterThan:
52+
return cmp > 0
53+
case GreaterThanOrEqual:
54+
return cmp >= 0
4655
default:
47-
panic(fmt.Errorf("cannot apply op '%s' to interface{}.", f.Op))
56+
panic(fmt.Errorf("unknown operation: %s", f.Op))
4857
}
4958
}
5059

0 commit comments

Comments
 (0)