紫衣仙女
Hash在您的实现中,当您为和初始化端点时,服务名称是错误的Validate。它应该pb.Vault代替Vault. 所以这个New方法应该是这样的: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, }}一般来说,你应该参考.pb.go匹配生成的文件proto来了解事物的命名方式。如您所见,这并不简单,可能取决于proto生成器的实现。在您的情况下,它看起来像这样: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",}