Convert dynamic interface to its equivalent type. For example if value is int it should return int and if is string so it return int.
Code example:
var options = bson.M{}
for _, val := range conditions {
var attr, operator, value interface{}
cons := val.(map[interface{}]interface{})
for range cons {
attr = cons["attribute"]
operator = cons["operator"]
value = cons["value"]
switch operator {
case "==":
operator = "$eq"
case "!=":
operator = "$ne"
case "()":
operator = "$in"
value = []string{fmt.Sprintf("%v", value)}
}
options[attr.(string)] = bson.M{operator.(string): value.
(int)}
}
}
Conditions come in below format.
conditions []interface{}
cons = append(cons, map[interface{}]interface{}{"attribute":
"discontinued", "operator": "!=", "value": 1})
cons = append(cons, map[interface{}]interface{}{"attribute": "status",
"operator": "==", "value": 1})
cons = append(cons, map[interface{}]interface{}{"attribute":
"visibility", "operator": "==", "value": 4})
But the "value": 4 OR "value": 1 is not confirm.
Error thrown: interface conversion: interface {} is string, not int