我使用
Golang
作为我的后端,使用 proto3
作为我的 API 定义。我有 grpc-gateway
来支持 http 和 grpc。
我的用例是拥有一个 webhook API,它可以获取一些有效负载并对其进行处理。我无法控制客户端,也无法确定有效负载结构。
如何定义我的请求对象?
示例:
service RepoService {
rpc PostGitPR(PostGitPREventRequest) returns (PostGitPREventResponse) {
option (google.api.http) = {
post: "/git/pr/event"
body: "*"
};
}
我使用
any.proto
还是[]byte
?我不确定两者都会起作用。
如果无法预测有效负载,您可以使用
google.api.HttpBody
作为原型文件中的请求对象。请参阅:https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto