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

huangapple go评论95阅读模式
英文:

grpc.WithInsecure is deprecated: use insecure.NewCredentials() instead

问题

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

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

insecure.NewCredentials()函数调用会给出一个警告:

grpc.WithInsecure已被弃用:请使用insecure.NewCredentials()代替。

我不确定如何使用这个新的函数调用,有没有示例可以参考?谢谢。

英文:

Hey I'm trying make a small test client with Go and Grpc,

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

The WithInsecure() function call gives a warning:
> grpc.WithInsecure is deprecated: use insecure.NewCredentials() instead.

I'm not sure how to use this new function call is there an example somewhere? Thanks

答案1

得分: 65

insecure.NewCredentials 函数返回一个 credentials.TransportCredentials 的实现。

你可以将其作为 DialOption 使用,使用 grpc.WithTransportCredentials

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

The function insecure.NewCredentials returns an implementation of credentials.TransportCredentials.

You can use it as a DialOption with grpc.WithTransportCredentials:

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

huangapple
  • 本文由 发表于 2021年12月26日 04:17:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/70482508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定