I have a service written in Go that get data from rest api and return that data as a grpc server. I got an array of object. And I want to return it through the grpc protobuf file. But it keeps failing because of type issue as the data from the api is []interface{} and I don't know how to return this through protobuf response.
Below is the go lang code
return &waas.BankListResponse{
Status: result.Data["Status"].(bool),
Message: result.Data["Message"].(string),
Data: result.Data["banks"].([]*waas.Banks),
}, nil
The proto file
message banks {
string bankCode = 1;
string bankName = 2;
}
message BankListResponse {
bool Status =1;
string Message = 2;
repeated banks data = 3;
}
So the result.Data["bank"]
is the array of banks and the data type is []interface{}
sample data
{
"banks": [
{
"bankCode":"",
"bankName":""
},
{
"bankCode":"",
"bankName":""
}
]
}
So can someone assist me point out how return such data on the proto file.