0

通常我们将服务器地址(例如“localhost:56666”或“someserver:9999”)传递给 grpc-go 的 Dial 方法。

例如:grpc.Dial("localhost:56666", grpc.WithInSecure())

但是在 grpc-go repo 给出的测试用例中(参考下面的链接), Dial 的第一个参数被称为 "*Dial( r.Scheme()+":///test.server" , WithInsecure(), WithTimeout (5*time.Second))*”。当我通过运行这些 go test 文件打印该值时,我观察到该地址值为“ bykrwuxel00s:///test.server

https://github.com/grpc/grpc-go/blob/master/balancer/roundrobin/roundrobin_test.go#L102

https://github.com/grpc/grpc-go/blob/master/clientconn_test.go#L135

这如何作为有效的服务器地址工作?

4

1 回答 1

0

gRPC URI 目标的“方案”元素基本上只指示目标的“类型”。有关详细信息,请参阅https://github.com/grpc/grpc/blob/master/doc/naming.md#name-syntax 。

例如,通过这种方式,gRPC 客户端可以查看该类型并决定使用哪种名称解析机制(在内部,每个“解析器”都在唯一的方案下注册)。

在这种情况下,该测试似乎使用了一个自定义解析器,它是通过调用“GenerateAndRegisterManualResolver”生成的,它动态生成了一个用于全局注册的独特方案:https ://github.com/grpc/grpc-go/blob /7c1d326729dc9b0a07135f8902ddcc050ff8ab64/resolver/manual/manual.go#L89

于 2019-11-20T18:39:07.887 回答