Skip to content

Instantly share code, notes, and snippets.

@karreiro
Created July 16, 2019 00:52
Show Gist options
  • Select an option

  • Save karreiro/205ec324706bd112b728afacb8b36adf to your computer and use it in GitHub Desktop.

Select an option

Save karreiro/205ec324706bd112b728afacb8b36adf to your computer and use it in GitHub Desktop.
func main() {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewGreeterClient(conn)
// Contact the server and print out its response.
name := defaultName
if len(os.Args) > 1 {
name = os.Args[1]
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.SayHello(ctx, &pb.HelloRequest{Name: name})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.Message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment