grpc-gateway: 定义(proto文件)与重定向不匹配

huangapple go评论78阅读模式
英文:

grpc-gateway: redirect missmatch with the defination (proto file)

问题

我使用grpc-gateway来为我的grpc服务托管REST API。

我有两个API:

API A

 option (google.api.http) = {
      post: "/v1/product/{id}"
      body: "*"
    };

API B

 option (google.api.http) = {
      post: "/v1/product/unit"
      body: "*"
    };

但是当我调用POST v1/product/unit时,grpc-gateway会重定向到API A的方法。我有什么遗漏吗?

英文:

I use grpc-gateway to host REST api for my grpc service.

I'm have 2 api:

API A

 option (google.api.http) = {
      post: "/v1/product/{id}"
      body: "*"
    };

API B

 option (google.api.http) = {
      post: "/v1/product/unit"
      body: "*"
    };

but when i call POST v1/product/unit
grpc-gateway redirect to the method with the API A.
Do i miss something?

答案1

得分: 0

这取决于你在网关多路复用器中注册 gRPC 服务器的顺序。这并不明显,但你应该先注册更一般的路径(/v1/product/{id}),然后再注册更精确的路径(/v1/product/uni)。然后,你应该改变在 grpc-gateway 的 ServeMux 中注册 gRPC 服务器的顺序。

英文:

It depends on order in which you register your gRPC servers in gateway mux. It's not obvious but you should register more general path (/v1/product/{id}) before more exact path (/v1/product/uni). Then you should change order of registration of your gRPC servers in grpc-gatewar ServeMux

huangapple
  • 本文由 发表于 2022年11月4日 20:08:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/74316837.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定