如何将JSON主体请求传递给Golang的地图字符串数据结构中的API?
我是Golang和GRPC的新手,需要指导和澄清。我有以下定义作为参数来调用外部API的发布请求。
params := map[string]string{
"movie": movie,
"seat": seat,
"pax": fmt.Sprint(pax),
"class": class,
}
在原始文件中,我有以下内容:
message TicketData {
string movie= 1;
string seat= 2;
uint32 pax= 3;
string class = 4;
}
message SearchMovieRequest {
TicketData data= 1;
}
但是,在Postman(GRPC请求)中,正文请求如下:
{
"data":
{
"movie": "abc",
"seat": "123",
"pax": 2,
"class ": "b""
}
}
请求主体应在下面:
{
"data": **[**
{
"movie": "abc",
"seat": "123",
"pax": 2,
"class ": "b""
}
**]** - missing brackets in my json body
}
我尝试使用structpb并映射字符串接口。它似乎不起作用。任何指针都将不胜感激。谢谢。
I am new to golang and grpc, need guidance and clarification. I have below definition as a parameter to call a POST request for an external API.
params := map[string]string{
"movie": movie,
"seat": seat,
"pax": fmt.Sprint(pax),
"class": class,
}
In proto file, I have below:
message TicketData {
string movie= 1;
string seat= 2;
uint32 pax= 3;
string class = 4;
}
message SearchMovieRequest {
TicketData data= 1;
}
However in POSTMAN (grpc request), the body request is showing below:
{
"data":
{
"movie": "abc",
"seat": "123",
"pax": 2,
"class ": "b""
}
}
the request body should be below:
{
"data": **[**
{
"movie": "abc",
"seat": "123",
"pax": 2,
"class ": "b""
}
**]** - missing brackets in my json body
}
I have tried using structpb and also map string interface. It doesn't seem to work. Any pointer will be appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您希望
数据
字段为重复ticketdata
。请参阅例如“ nofollow noreferrer”>指定字段规则://developers.google.com/protocol-buffers/docs/proto3“ rel =“ nofollow noreferrer”>语言指南(proto3)。
具体来说:
You want the
data
field to berepeated TicketData
.See e.g. Specifying Field Rules in the Protobuf Language Guide (proto3).
Specifically: