MCPcopy Create free account
hub / github.com/apache/thrift / handleClient

Function handleClient

tutorial/go/src/client.go:32–79  ·  view source on GitHub ↗
(client *tutorial.CalculatorClient)

Source from the content-addressed store, hash-verified

30var defaultCtx = context.Background()
31
32func handleClient(client *tutorial.CalculatorClient) (err error) {
33 client.Ping(defaultCtx)
34 fmt.Println("ping()")
35
36 sum, _ := client.Add(defaultCtx, 1, 1)
37 fmt.Print("1+1=", sum, "\n")
38
39 work := tutorial.NewWork()
40 work.Op = tutorial.Operation_DIVIDE
41 work.Num1 = 1
42 work.Num2 = 0
43 quotient, err := client.Calculate(defaultCtx, 1, work)
44 if err != nil {
45 switch v := err.(type) {
46 case *tutorial.InvalidOperation:
47 fmt.Println("Invalid operation:", v)
48 default:
49 fmt.Println("Error during operation:", err)
50 }
51 } else {
52 fmt.Println("Whoa we can divide by 0 with new value:", quotient)
53 }
54
55 work.Op = tutorial.Operation_SUBTRACT
56 work.Num1 = 15
57 work.Num2 = 10
58 diff, err := client.Calculate(defaultCtx, 1, work)
59 if err != nil {
60 switch v := err.(type) {
61 case *tutorial.InvalidOperation:
62 fmt.Println("Invalid operation:", v)
63 default:
64 fmt.Println("Error during operation:", err)
65 }
66 return err
67 } else {
68 fmt.Print("15-10=", diff, "\n")
69 }
70
71 log, err := client.GetStruct(defaultCtx, 1)
72 if err != nil {
73 fmt.Println("Unable to get struct:", err)
74 return err
75 } else {
76 fmt.Println("Check log:", log.Value)
77 }
78 return err
79}
80
81func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool, cfg *thrift.TConfiguration) error {
82 var transport thrift.TTransport

Callers 1

runClientFunction · 0.85

Calls 4

PingMethod · 0.45
AddMethod · 0.45
CalculateMethod · 0.45
GetStructMethod · 0.45

Tested by

no test coverage detected