THRIFT-4260 Go context generation issue. Context is parameter in Interface not in implementation
Client: Go
Patch: taozle <zhangliyang26@gmail.com>
This closes #1312
diff --git a/tutorial/go/src/client.go b/tutorial/go/src/client.go
index 9106ac9..65027ea 100644
--- a/tutorial/go/src/client.go
+++ b/tutorial/go/src/client.go
@@ -27,17 +27,17 @@
)
func handleClient(client *tutorial.CalculatorClient) (err error) {
- client.Ping()
+ client.Ping(defaultCtx)
fmt.Println("ping()")
- sum, _ := client.Add(1, 1)
+ sum, _ := client.Add(defaultCtx, 1, 1)
fmt.Print("1+1=", sum, "\n")
work := tutorial.NewWork()
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 1
work.Num2 = 0
- quotient, err := client.Calculate(1, work)
+ quotient, err := client.Calculate(defaultCtx, 1, work)
if err != nil {
switch v := err.(type) {
case *tutorial.InvalidOperation:
@@ -53,7 +53,7 @@
work.Op = tutorial.Operation_SUBTRACT
work.Num1 = 15
work.Num2 = 10
- diff, err := client.Calculate(1, work)
+ diff, err := client.Calculate(defaultCtx, 1, work)
if err != nil {
switch v := err.(type) {
case *tutorial.InvalidOperation:
@@ -66,7 +66,7 @@
fmt.Print("15-10=", diff, "\n")
}
- log, err := client.GetStruct(1)
+ log, err := client.GetStruct(defaultCtx, 1)
if err != nil {
fmt.Println("Unable to get struct:", err)
return err
diff --git a/tutorial/go/src/go17.go b/tutorial/go/src/go17.go
new file mode 100644
index 0000000..a6003a9
--- /dev/null
+++ b/tutorial/go/src/go17.go
@@ -0,0 +1,26 @@
+// +build go1.7
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package main
+
+import "context"
+
+var defaultCtx = context.Background()
diff --git a/tutorial/go/src/pre_go17.go b/tutorial/go/src/pre_go17.go
new file mode 100644
index 0000000..10a6fb8
--- /dev/null
+++ b/tutorial/go/src/pre_go17.go
@@ -0,0 +1,26 @@
+// +build !go1.7
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package main
+
+import "golang.org/x/net/context"
+
+var defaultCtx = context.Background()