【问题标题】:How to call a gRPC function which return empty [duplicate]如何调用返回空的gRPC函数[重复]
【发布时间】:2021-04-26 08:11:30
【问题描述】:

这里是文件ns.pb.go中函数的定义

CreateMACCommandQueueItem(ctx context.Context, in *CreateMACCommandQueueItemRequest, opts ...grpc.CallOption) (*empty.Empty, error)

这是我编写的 main.go 代码的一部分:

resp, err := serviceClient.CreateMACCommandQueueItem(context.Background(), &ns.CreateMACCommandQueueItemRequest{
    DevEui:     devEUI[:],
    Cid:        uint32(lorawan.LinkADRReq),
    Commands:   [][]byte{b},
})

if err != nil {
        panic(err)
}

fmt.Printf("The MACCommand has been enqueued")

这是错误:

.\main.go:62:2: resp declared but not used

【问题讨论】:

    标签: go grpc grpc-go


    【解决方案1】:

    你可以这样写:

    if _, err := serviceClient.CreateMACCommandQueueItem(context.Background(), &ns.CreateMACCommandQueueItemRequest{
        DevEui:     devEUI[:],
        Cid:        uint32(lorawan.LinkADRReq),
        Commands:   [][]byte{b},
    
    }): err != nil {
        panic(err)
    }
    

    【讨论】:

    • 对程序结构做了一些调整,真的很新颖。
    猜你喜欢
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 2018-07-17
    • 1970-01-01
    • 2021-10-19
    相关资源
    最近更新 更多