-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
44 lines (38 loc) · 908 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"context"
"fmt"
greetpb "github.com/infracloudio/grpc-blog/greet_app/internal/pkg/proto"
"google.golang.org/grpc"
"log"
"os"
)
func main() {
fmt.Println("Starting greet client")
opts := grpc.WithInsecure()
servAddr := ":50059"
if len(os.Getenv("GRPC_SRV_ADDR")) > 0 {
servAddr = os.Getenv("GRPC_SRV_ADDR")
}
cc, err := grpc.Dial(servAddr, opts)
if err != nil {
log.Fatalf("could not connect: %v", err)
}
defer cc.Close()
c := greetpb.NewGreetServiceClient(cc)
doUnary(c)
}
func doUnary(c greetpb.GreetServiceClient) {
log.Println("starting unary.....")
req := &greetpb.GreetingRequest{
Greeting: &greetpb.Greeting{
FirstName: "Hitesh",
LastName: "Pattanayak",
},
}
res, err := c.Greet(context.Background(), req)
if err != nil {
log.Fatalf("error while calling greet rpc : %v", err)
}
log.Printf("reponse from Greet rpc: %v", res.Result)
}