英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论