Missing JSON fields vs panic
I want to use this rules engine to check iot data.
Since the data coming it can be dynamic or even just partial data, i wanted to ask what is the recommended way for handling those rules.
Basically im working with Json data and i dont know if i should add a nil check for all the fields used in the rule as the first part of the rule or if i should let it panic.
Would be great to have a property (something like AllowMissingFacts) the will skip over the rule if one of the values are missing
i guess an alternative is to check all the facts relevant to the rule first, but it seems a bit verbose
It is painful to check nil values when dealing with json data, AllowMissingFacts/AllowMissingFields will be a good idea. But for now i would recommend keep each field having default value, which is not that hard to deal with in Go. As for ptr, use reflect to auto fill the ptr might work, then convert to json data.
The problem with default values is that for numeric Felds its 0 and i have no way of knowing if the value is is 0 or not.
We use it for iot data so it could be a Boolean indicator.
I set empty fields to nil for now bit it requires having to clean up on the other side
Implemented partially logic to handle nils in code (e.g. due to JSON facts with relaxed schema). Handled already "normal" operators and also e.g. string function calls for left hand side nil.
Now considering how to handle the "input" nils as results depend on the function self. Technically rule itself could have nil check (https://github.com/hyperjumptech/grule-rule-engine/blob/master/docs/en/Function_en.md#isnili-interface-bool), but it would be quite confusing at rules.