My problem is pretty simple, I would like to dynamically create filters to use it in my query input. I must precise that the tf variable can't change.
So here is what I did :
totalFilter := expression.ConditionBuilder{}
filter := expression.Name("status").Equal(expression.Value("0"))
filter2 := expression.Name("foo").Equal(expression.Value("bar"))
filter3 := expression.Name("yes").Equal(expression.Value("no"))
tf := []expression.ConditionBuilder{filter, filter2, filter3}
for _, v := range tf {
totalFilter = totalFilter.And(v)
}
expr := expression.NewBuilder().WithFilter(totalFilter)
builder, err := expr.Build()
if err != nil {
log.Println(err)
return err
}
But the probleme is that totalFilter is an empty struct so it's mode variable is equal to 0 and then it raise an alert because mode 0 is unsetCond.
The only workaround that I found is to do this :
for i, v := range tf {
if i == 0 {
totalFilter = v
} else {
totalFilter.And(v)
}
}
But I was wondering if there is another solution.