go-zero
go-zero copied to clipboard
some feature request about gateway
Get parameters from request headers or context, and set them to rpc request parameters
I have an rpc interface called SetUserInfo
, Its request parameters are as follows:
message ReqSetUserInfo {
string selfId = 1; // requester's user id
string ip = 2; // requester's ip address
string nickname = 3;
}
The client does not need to set the selfId
and ip
when calling the http api. Because the requester id can be obtained in the authMiddleware
, and the requester ip can be obtained in the request header
.
So I need you to provide a way to set the value I need in the context or the value in the request header as the rpc request parameter.
maybe as follows:
Support for custom api response wrapper In most cases, the response of rpc cannot be used as the final response of api. One of the response structures we use the most is as follows:
{
"code": 0,
"msg": "success",
"data": {
"id": "xxx"
}
}
or:
{
"code": -1,
"msg": "forbidden"
}
Now, gateway doesn't provide a way to customize response wrapping
I may need to write the rpc response into $.data
, and maybe set the code value to -1
.
My current solution is as follows:
Use proto set bytes instead of filename I can use go:embed to embed files during compilation, but it's not necessary.
一般网关都要折叠grpc 的数据 ,然后带上code 和msg 没有企业级最佳实践,得自己改
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Generally, the gateway must fold the grpc data, and then bring the code and msg. There is no enterprise-level best practice, so you have to change it yourself
I can modify the goctl template code to achieve