runtime.ServeMux: 选择了错误的处理程序
□ 错误报告
[将自定义路线添加到mux |-gRPC-Gateway](https://grpc-ecosystem.ZGitHub.io/grpc-gateway/docs/operations/inject router/). 翻译: gRPC- Gateway 允许您在 service mux 中添加自定义路由, 例如, 如果您想要支持 gRPC- Gateway 不支持的用例, 如文件上传 。
因此,我有一个ListFiles方法在gRPC服务原型中列出文件:"/v3/files".
我用“HandlePath”手动登记了另一种“GetFile”方法:/v3/files/{path=**}>。
最终的通路树可能如下:
开始
func 主 () {
mux:=运行时间. NewServeMux ()
mu. HandlePath(GET',/v3/files', func (w http. 反应Writer, r *. http. request, pathParams map [string] string) {
fmt.Fprintln(w, 1, pathParams) (英语).
) (中文(简体) ).
mux.HandlePath(GET',/v3/files/{path=**}', func(w http.ResponseWriter, r *http. request, pathParams map[string] string){ fmt.Fprintln(w, 2, pathParams) (英语). ) (中文(简体) ). http.learningAndServe(:8080', mux) (中文(简体) ).
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?
结果 :
嘘
折叠本地主机: 8080/v3/ 文件
2 地图[路径:]
卷曲本地主机:8080/v3/文件/ a.txt
2 地图[路径:a.txt]我期望第一个请求是 引导第一个处理器,它打印出1。
拆卸处理命令可以解决这个问题 但我认为处理命令不应该重要:
- https://GitHub.com/grpc-ecosystem/grpc-gateway/blob/031e8453ef0293ed15626100d8799a1bec2347/runtim/mux.go#L354
- https://GitHub.com/grpc-ecosystem/grpc-gateway/blob/031e8453ef0293ed15626100d8799a1becc2347/runtim/mux.go#L412
后加的接取器会被放入接取器切片前方,并首先被使用.
内容来源: grpc-ecosystem/grpc-gateway