有没有办法用不安全的连接在 grpc-dart 中设置主机,我看过这个但找不到方法?
只需要设置:authority
它应该类似于 go - example setting host serverHostOverride
:(注意我可以设置 host 并运行 WithInsecure 连接)
var (
serverAddr = flag.String("server_addr", "127.0.0.1:8080", "The server address in the format of host:port")
serverHostOverride = flag.String("server_host_override", "", "")
insecure = flag.Bool("insecure", false, "Set to true to skip SSL validation")
)
func main() {
flag.Parse()
var opts []grpc.DialOption
if *serverHostOverride != "" {
opts = append(opts, grpc.WithAuthority(*serverHostOverride))
}
if *insecure {
opts = append(opts, grpc.WithInsecure())
}
conn, err := grpc.Dial(*serverAddr, opts...)
if err != nil {
log.Fatalf("fail to dial: %v", err)
}
defer conn.Close()
client := pb.NewPingServiceClient(conn)
ping(client, "hello")
pingStream(client, "hello")
}