You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the IN operator the right side (RHS) of the expression must be an instance of []interface. This, for instance, makes it frustrating when working the Subscriptions field ([]string) on the Check and Entity types.
Expected Behavior
I would expect to be able write the expression 'unix' IN entity.Subscriptions, however since the RHS of the expression is a slice of strings, this will always evaluate to false.
Possible Solution
A few possible avenues.
a) Expose a function
We could expose a function (eg. sliceContains) that allows the user to check if an identifier has a specified value.
To avoid any confusion it may make sense to simply remove IN.
// Example expressionentity.LastSeen>12345678&&sliceContains(entity.Subscriptions, 'unix')
Drawbacks
Lots of type assertions, I guess
Functions require extra documentation
Without any sort of module/packages/namespaces, we run the risk of identifiers colliding
b) Add to types package
I believe, we potentially could add a type with some helpful methods familiar to those who write Python and Ruby.
When using the
IN
operator the right side (RHS) of the expression must be an instance of[]interface
. This, for instance, makes it frustrating when working theSubscriptions
field ([]string
) on theCheck
andEntity
types.Expected Behavior
I would expect to be able write the expression
'unix' IN entity.Subscriptions
, however since the RHS of the expression is a slice of strings, this will always evaluate tofalse
.Possible Solution
A few possible avenues.
a) Expose a function
sliceContains
) that allows the user to check if an identifier has a specified value.IN
.Drawbacks
b) Add to types package
I believe, we potentially could add a type with some helpful methods familiar to those who write Python and Ruby.
Drawbacks
c) Expand govaluate
Update
govaluate
so thatIN
operator can handle greater range of expressions.I figure this could partially be optimized at the planning stage;
[]interface
[]string
,[]int
,[]float
, etc.(1 + 3 / 6.0) IN myIdentifier
myIdentifier IN otherIdentifer
Drawbacks
Context
The text was updated successfully, but these errors were encountered: