THRIFT-2349: Golang - improve tutorial
authorJens Geyer <jensg@apache.org>
Wed, 5 Feb 2014 20:10:59 +0000 (21:10 +0100)
committerJens Geyer <jensg@apache.org>
Wed, 5 Feb 2014 20:10:59 +0000 (21:10 +0100)
Patch: Chris Bannister

tutorial/go/src/client.go

index 31376f8..a497d7f 100644 (file)
@@ -39,10 +39,13 @@ func handleClient(client *tutorial.CalculatorClient) (err error) {
        work.Num2 = 0
        quotient, err := client.Calculate(1, work)
        if err != nil {
-               fmt.Println("Error during operation:", err)
+               switch v := err.(type) {
+               case *tutorial.InvalidOperation:
+                       fmt.Println("Invalid operation:", v)
+               default:
+                       fmt.Println("Error during operation:", err)
+               }
                return err
-       //} else if ouch != nil {
-       //      fmt.Println("Invalid operation:", ouch)
        } else {
                fmt.Println("Whoa we can divide by 0 with new value:", quotient)
        }
@@ -52,10 +55,13 @@ func handleClient(client *tutorial.CalculatorClient) (err error) {
        work.Num2 = 10
        diff, err := client.Calculate(1, work)
        if err != nil {
-               fmt.Println("Error during operation:", err)
+               switch v := err.(type) {
+               case *tutorial.InvalidOperation:
+                       fmt.Println("Invalid operation:", v)
+               default:
+                       fmt.Println("Error during operation:", err)
+               }
                return err
-       //} else if ouch != nil {
-       //      fmt.Println("Invalid operation:", ouch)
        } else {
                fmt.Print("15-10=", diff, "\n")
        }