-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
40 lines (32 loc) · 864 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
package main
import (
"context"
"github.com/fwani/gRPC-Test/aggfuncs"
"log"
"time"
"google.golang.org/grpc"
)
func main() {
conn, err := grpc.Dial("127.0.0.1:4321", grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v\n", err)
}
defer conn.Close()
client := agg.NewGRPCRouteFuncsClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
var x int32
var y int32
x = 5
y = 3
res, err := client.Sum(ctx, &agg.InputArgsOfBinaryFunc{Value1: x, Value2: y})
if err != nil {
log.Fatalf("could not request: %v\n", err)
}
log.Printf("sum: %d + %d = %v\n", x, y, res)
res, err = client.Multiply(ctx, &agg.InputArgsOfBinaryFunc{Value1: x, Value2: y})
if err != nil {
log.Fatalf("could not request: %v\n", err)
}
log.Printf("multiply: %d * %d = %v\n", x, y, res)
}