通常,我们将服务器地址(例如“ 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测试文件打印该值时,我观察到该地址值为“ 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
这是有效的服务器地址吗?
答案 0 :(得分:0)
gRPC URI目标的“ scheme”元素基本上仅指示目标的“类型”。有关更多详细信息,请参见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