tlsclient.go 605 Bytes
package main

import (
	"context"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
	"log"
	"pro2d/protos/pb"
)

func main() {
	var opts []grpc.DialOption
	creds, err := credentials.NewClientTLSFromFile("keys/server.pem", "pro2d")
	if err != nil {
		log.Fatal(err)
		return
	}
	opts = append(opts, grpc.WithTransportCredentials(creds))
	conn, err := grpc.Dial("localhost:8948", opts...)

	helloClient := pb.NewHelloClient(conn)
	rsp, err := helloClient.SayHello(context.TODO(), &pb.HelloWorld{Msg: "hello world"})
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("sayhello rsp: %v", rsp)
}