字段
字段 | 类型 | 描述 |
code | number | 状态码 |
data | any | 业务返回数据 |
headers | Record<string, string[]> | 请求 Header 元数据 |
message | string | 错误信息 |
trailers | Record<string, string[]> | 请求 Trailer 元数据 |
样例
调用 Client.invoke 获得请求返回对象:
import grpc from 'pts/grpc';// 创建新的 grpc Clientconst client = new grpc.Client();// 加载协议文件根目录中的 addsvc.protoclient.load([], 'addsvc.proto');export default () => {// 建立连接client.connect('grpcb.in:9000', { insecure: true });// 调用方法,获得请求的返回对象 rspconst rsp = client.invoke('addsvc.Add/Sum', {a: 1,b: 2,});console.log(rsp.data.v); // 3// 关闭连接client.close();};