Created
December 30, 2019 22:24
-
-
Save gistlyn/f6b0aa85439889228dbdce8088dcbbe0 to your computer and use it in GitHub Desktop.
Go Google protoc SSL GrpcServicesClient TodoWorld Example
This file contains hidden or 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 "context" | |
"fmt" | |
"log" | |
"google.golang.org/grpc" | |
"google.golang.org/grpc/credentials" | |
pb "TodoWorld/services" | |
"time" | |
) | |
func main() { | |
creds, err := credentials.NewClientTLSFromFile("grpc.crt", "") | |
if err != nil { | |
log.Fatalf("could not process the credentials: %v", err) | |
} | |
conn, err := grpc.Dial("todoworld.servicestack.net:50051", grpc.WithTransportCredentials(creds)) | |
if err != nil { | |
log.Fatalf("fail to dial: %v", err) | |
} | |
defer conn.Close() | |
client := pb.NewGrpcServicesClient(conn) | |
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | |
defer cancel() | |
response, err := client.GetHello(ctx, &pb.Hello{Name: "gRPC Go"}) | |
if err != nil { | |
log.Fatalf("GetHello: %v", err) | |
} | |
fmt.Println(response.Result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment