From: Julien Andrieux Date: Thu, 5 Oct 2017 15:36:26 +0000 (+0200) Subject: Add SSL support on the client X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=cf1968ca31944dc8bfb1d174317ce8b4b12e158b;p=demo-grpc.git Add SSL support on the client --- diff --git a/client/main.go b/client/main.go index 1151776..5df1cdd 100644 --- a/client/main.go +++ b/client/main.go @@ -6,12 +6,20 @@ import ( "gitlab.com/pantomath-io/demo-grpc/api" "golang.org/x/net/context" "google.golang.org/grpc" + "google.golang.org/grpc/credentials" ) func main() { var conn *grpc.ClientConn - conn, err := grpc.Dial(":7777", grpc.WithInsecure()) + // Create the client TLS credentials + creds, err := credentials.NewClientTLSFromFile("cert/server.crt", "") + if err != nil { + log.Fatalf("could not load tls cert: %s", err) + } + + // Initiate a connection with the server + conn, err = grpc.Dial("localhost:7777", grpc.WithTransportCredentials(creds)) if err != nil { log.Fatalf("did not connect: %s", err) } @@ -21,7 +29,7 @@ func main() { response, err := c.SayHello(context.Background(), &api.PingMessage{Greeting: "foo"}) if err != nil { - log.Fatalf("Error when calling SayHello: %s", err) + log.Fatalf("error when calling SayHello: %s", err) } log.Printf("Response from server: %s", response.Greeting) }