【发布时间】:2021-09-05 08:41:42
【问题描述】:
我是使用带有 proto3 的 gRPC 的新手,我使用 Transcoding HTTP/JSON to gRPC 将现有的 http 端点迁移到 grpc。
但是我有带有请求正文的 http DELETE 请求。我已尝试关注,但出现错误。
Grpc 端点:
rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse) {
option (google.api.http) = {
delete: "/v2/file/delete/{path}"
body: "*"
};
}
protoc gererate 命令如下
protoc -I ./proto --go-grpc_out=. --go_out=. --grpc-gateway_out=. --openapiv2_out=./openapi ./proto/myapp.proto
我遇到了错误
--grpc-gateway_out: must not set request body when http method is DELETE except allow_delete_body option is true
然后我将--allow_delete_body=true 添加到我的 protoc 命令中,如下所示。
--allow_delete_body=true
error : Unknown flag: --allow_delete_body
--grpc-gateway_opt allow_delete_body=true
error : must not set request body when http method is DELETE except allow_delete_body option is true
我的 go.mod 中的 grpc 版本
github.com/grpc-ecosystem/grpc-gateway/v2 v2.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
google.golang.org/genproto v0.0.0-20210224155714-063164c882e6
google.golang.org/grpc v1.36.0
google.golang.org/protobuf v1.26.0
谁能解释一下我如何将 HTTP DELETE 转码为带有请求正文的 grpc。
【问题讨论】:
标签: http grpc http2 grpc-go grpc-gateway