Last active
August 6, 2021 11:35
-
-
Save percybolmer/a74a7fff4c3da97ada150c26f090e0e7 to your computer and use it in GitHub Desktop.
a simple main function that loads tls connection and calls ping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"crypto/tls" | |
"crypto/x509" | |
"io/ioutil" | |
"log" | |
"github.com/percybolmer/grpcexample/pingpong" | |
"google.golang.org/grpc" | |
"google.golang.org/grpc/credentials" | |
) | |
func main() { | |
ctx := context.Background() | |
// Load our TLS certificate and use grpc/credentials to create new transport credentials | |
creds := credentials.NewTLS(loadTLSCfg()) | |
// Create a new connection using the transport credentials | |
conn, err := grpc.DialContext(ctx, "localhost:9990", grpc.WithTransportCredentials(creds)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer conn.Close() | |
// A new GRPC client to use | |
client := pingpong.NewPingPongClient(conn) | |
pong, err := client.Ping(ctx, &pingpong.PingRequest{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Println(pong) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment