I am writing a new service in golang using protobuf. I want to model the following Request JSON in the .proto file.
[
{
"var": ["myVariable1","myVariable2"],
"key1": 123123,
"key2": 1122,
"key3": "abcd-0101"
},
{
"var": ["myVariable1"],
"key1": 123124,
"key2": 1123,
"key3": "abcd-0102"
},
]
There are two problems currently :
- The keys in each array element are not known beforehand, hence I cannot create a message in .proto file and make it repeated. I need to keep it map
- I am unable to model a json which is just an array with no key. Everytime i do this, following error is shown : failed to decode request: json: cannot unmarshal array into Go value
Following is my .proto file :
syntax = "proto3";
package pb;
import "google/protobuf/empty.proto";
import "google/api/annotations.proto";
service Transmitter {
rpc GetVariables(GetVariablesRequest) returns (GetVariablesResponse) {
option (google.api.http) = {
post: "/api/v1/{Service}/getVars"
body: "*"
};
};
}
message GetVariablesRequest {
string Service = 1;
repeated GetVarInput in = 2;
}
message GetVariablesResponse {
string msg = 1;
}
message GetVarInput {
map<string,string> Input = 2;
}
I have tried with bytes instead of repeated GetVarInput, but it always comes empty. Also tried body: "*" and body : "in"
Please provide some pointers.