1 回答

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
Hash在您的實(shí)現(xiàn)中,當(dāng)您為和初始化端點(diǎn)時(shí),服務(wù)名稱是錯(cuò)誤的Validate。它應(yīng)該pb.Vault代替Vault. 所以這個(gè)New方法應(yīng)該是這樣的:
func New(conn *grpc.ClientConn) vault.Service {
var hashEndpoint = grpctransport.NewClient(
conn, "pb.Vault", "Hash",
vault.EncodeGRPCHashRequest,
vault.DecodeGRPCHashResponse,
pb.HashResponse{},
).Endpoint()
var validateEndpoint = grpctransport.NewClient(
conn, "pb.Vault", "Validate",
vault.EncodeGRPCValidateRequest,
vault.DecodeGRPCValidateResponse,
pb.ValidateResponse{},
).Endpoint()
return vault.Endpoints{
HashEndpoint: hashEndpoint,
ValidateEndpoint: validateEndpoint,
}
}
一般來說,你應(yīng)該參考.pb.go匹配生成的文件proto來了解事物的命名方式。如您所見,這并不簡(jiǎn)單,可能取決于proto生成器的實(shí)現(xiàn)。
在您的情況下,它看起來像這樣:
grpc.ServiceDesc{
ServiceName: "pb.Vault",
HandlerType: (*VaultServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Hash",
Handler: _Vault_Hash_Handler,
},
{
MethodName: "Validate",
Handler: _Vault_Validate_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "vault.proto",
}
- 1 回答
- 0 關(guān)注
- 158 瀏覽
添加回答
舉報(bào)