Hello, I have in go data like:
bla := []map[string]interface{}{
{
Name: "data1",
Fields: map[string]interface{}{
"Field1": true,
"Field2": map[string]interface{}{
"Key": "foo",
},
"Field3": []map[string]interface{}{
{
"Key": "Bar",
"InnerField": []map[string]interface{}{
{
"Key": "Bar",
"Array": []int{1, 2}
},
{
"Key": "Baz",
"Array": []int{3, 4}
},
},
},
{
"Key": "Foo",
"InnerField": []map[string]interface{}{
{
"Key": "Rab",
"Array": []int{342, 234}
},
{
"Key": "Zab",
"Array": []int{534, 3453}
},
},
},
},
},
},
}
It is only the example, there will be much more fields and the names of each field can be random (like Field3
or FieldNone
). I have to keep it as map[string]interface
I am not able to make from it struct
My question is if I am able to in easy way to, for example, filtering,sorting,paginating over that complicated struct? In my head it should looks like:
filter := map[string]interface{}{
"Fields.Fields3[].InnerField.Key": "Bar"
}
res := db.Get(filter)
So I have got res
like:
map[string]interface{}{
Name: "data1",
Fields: map[string]interface{}{
"Field1": true,
"Field2": map[string]interface{}{
"Key": "foo",
},
"Field3": []map[string]interface{}{
{
"Key": "Bar",
"InnerField": []map[string]interface{}{
{
"Key": "Bar",
"Array": []int{1, 2}
},
{
"Key": "Baz",
"Array": []int{3, 4}
},
},
},
},
},
}
or
filter := map[string]interface{}{
"Name": "data2"
}
res := db.Get(filter)
res == []map[string]interface{} // res is empty