将主机设置为grpc-dart

时间:2019-05-15 14:08:20

标签: dart grpc grpc-go

是否可以通过不安全的连接在grpc-dart中设置Host,我看过this但找不到方法?

只需设置:authority

它应该类似于go-示例设置主机serverHostOverride :(请注意,我可以设置主机并运行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")
}

0 个答案:

没有答案