go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

some feature request about gateway

Open showurl opened this issue 2 years ago • 0 comments

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: image

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: image

Use proto set bytes instead of filename I can use go:embed to embed files during compilation, but it's not necessary.

showurl avatar Aug 10 '22 08:08 showurl

一般网关都要折叠grpc 的数据 ,然后带上code 和msg 没有企业级最佳实践,得自己改

maomao94 avatar Aug 11 '22 08:08 maomao94

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

Issues-translate-bot avatar Aug 11 '22 08:08 Issues-translate-bot

I can modify the goctl template code to achieve

showurl avatar Aug 16 '22 06:08 showurl