-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApplyInterface does not support int number values #77
Comments
Not sure if this is a bug since json (and javascript) does not have integer as a native type. So, if you want to use
(source: https://pkg.go.dev/encoding/json) So, to your code work, just ensure that all numbers are float64: func TestIssue77(t *testing.T) {
rule := map[string]interface{}{
"==": []interface{}{
map[string]interface{}{
"var": "impact_levels",
},
float64(1),
},
}
data := map[string]interface{}{
"impact_levels": float64(1),
}
output, err := ApplyInterface(rule, data)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, output.(bool))
} |
My problem is that my rule is defined in a yaml:
it gets unmarshaled to such a struct:
and yaml.unmarshal will make this an int and not a float. so it would be really nice if the package could handle also integers correctly |
@diegoholiveira I quickly attempted to fix this while checking one of the flagd issues (see - open-feature/flagd-testbed#115). As you said, JSON parsing should work normally as Go uses float64 by default so this was not relevant for us. But anyway, see #78 for a fix proposal for int parsing. I think I covered possible parsing locations. Feel free to modify it if you see the need for more changes |
@Kavindu-Dodan LGTM. I'll merge it but probably it would be good to remove the Thanks |
Welcome, happy to help you with the PR. Yeah, agree. I think |
Hi, sorry to reopen the discussion here. On the matter of To replace it with |
@eltonjr since the data is coming from filesystem or http call, |
this returns an error, the reason seems to be that isNumber is checking for reflect.Float64, and therefor the int is assumed to be a string.
The text was updated successfully, but these errors were encountered: