【问题标题】:grpc.WithInsecure is deprecated: use insecure.NewCredentials() insteadgrpc.WithInsecure 已弃用:改用 insecure.NewCredentials()
【发布时间】:2022-01-25 15:39:59
【问题描述】:

嘿,我正在尝试使用 Go 和 Grpc 制作一个小型测试客户端,

opts := grpc.WithInsecure()
    cc, err := grpc.Dial("localhost:9950", opts)
    if err != nil {
        log.Fatal(err)
    }

WithInsecure() 函数调用给出警告:

grpc.WithInsecure 已弃用:改用 insecure.NewCredentials()。

我不确定如何使用这个新的函数调用,是否有示例?谢谢

【问题讨论】:

    标签: go grpc grpc-go


    【解决方案1】:

    函数insecure.NewCredentials()返回credentials.TransportCredentials的实现。

    您可以将其用作DialOptiongrpc.WithTransportCredentials

    grpc.Dial(":9950", grpc.WithTransportCredentials(insecure.NewCredentials()))
    

    【讨论】:

    • 作为 v1.44.0(2022 年 1 月 25 日)的更新,它不再是实验性的。此外,staticcheck linter 报告了这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 2014-02-12
    • 2017-01-22
    • 2016-02-17
    • 2014-12-25
    • 2011-02-17
    相关资源
    最近更新 更多