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/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index a82ce72..bac1c57 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -261,8 +261,7 @@
std::string function_signature(t_function* tfunction, std::string prefix = "");
std::string function_signature_if(t_function* tfunction,
std::string prefix = "",
- bool addError = false,
- bool enableContext = false);
+ bool addError = false);
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
std::string type_to_go_type(t_type* ttype);
@@ -1838,7 +1837,7 @@
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
generate_go_docstring(f_types_, (*f_iter));
- f_types_ << indent() << function_signature_if(*f_iter, "", true, true) << endl;
+ f_types_ << indent() << function_signature_if(*f_iter, "", true) << endl;
}
}
@@ -1952,7 +1951,7 @@
// Open function
generate_go_docstring(f_types_, (*f_iter));
f_types_ << indent() << "func (p *" << serviceName << "Client) "
- << function_signature_if(*f_iter, "", true, false) << " {" << endl;
+ << function_signature_if(*f_iter, "", true) << " {" << endl;
indent_up();
/*
f_types_ <<
@@ -2160,9 +2159,15 @@
string unused_protection;
+ string ctxPackage = "context";
+ if (legacy_context_) {
+ ctxPackage = "golang.org/x/net/context";
+ }
+
f_remote << go_autogen_comment();
f_remote << indent() << "package main" << endl << endl;
f_remote << indent() << "import (" << endl;
+ f_remote << indent() << " \"" << ctxPackage << "\"" << endl;
f_remote << indent() << " \"flag\"" << endl;
f_remote << indent() << " \"fmt\"" << endl;
f_remote << indent() << " \"math\"" << endl;
@@ -2502,9 +2507,11 @@
f_remote << indent() << "fmt.Print(client." << pubName << "(";
bool argFirst = true;
+ f_remote << "context.Background()";
for (std::vector<t_field*>::size_type i = 0; i < num_args; ++i) {
if (argFirst) {
argFirst = false;
+ f_remote << ", ";
} else {
f_remote << ", ";
}
@@ -3434,15 +3441,12 @@
* Renders an interface function signature of the form 'type name(args)'
*
* @param tfunction Function definition
- * @param enableContext Client doesn't suppport context for now.
* @return String of rendered function definition
*/
-string t_go_generator::function_signature_if(t_function* tfunction, string prefix, bool addError, bool enableContext) {
+string t_go_generator::function_signature_if(t_function* tfunction, string prefix, bool addError) {
// TODO(mcslee): Nitpicky, no ',' if argument_list is empty
string signature = publicize(prefix + tfunction->get_name()) + "(";
- if (enableContext) {
- signature += "ctx context.Context, ";
- }
+ signature += "ctx context.Context, ";
signature += argument_list(tfunction->get_arglist()) + ") (";
t_type* ret = tfunction->get_returntype();
t_struct* exceptions = tfunction->get_xceptions();
diff --git a/configure.ac b/configure.ac
index 0c628da..bb036f0 100755
--- a/configure.ac
+++ b/configure.ac
@@ -398,6 +398,7 @@
if [[ -x "$GO" ]] ; then
AS_IF([test -n "$GO"],[
ax_go_version="1.4"
+ ax_go17_version="1.7"
AC_MSG_CHECKING([for Go version])
golang_version=`$GO version 2>&1 | $SED -e 's/\(go \)\(version \)\(go\)\(@<:@0-9@:>@.@<:@0-9@:>@.@<:@0-9@:>@\)\(@<:@\*@:>@*\).*/\4/'`
@@ -410,6 +411,13 @@
:
have_go="no"
])
+ AX_COMPARE_VERSION([$golang_version],[lt],[$ax_go17_version],[
+ :
+ go_version_lt_17="yes"
+ ],[
+ :
+ go_version_lt_17="no"
+ ])
],[
AC_MSG_WARN([could not find Go ])
have_go="no"
@@ -417,6 +425,7 @@
fi
fi
AM_CONDITIONAL(WITH_GO, [test "$have_go" = "yes"])
+AM_CONDITIONAL([GOVERSION_LT_17], [test "$go_version_lt_17" = "yes"])
AX_THRIFT_LIB(rs, [Rust], yes)
have_rs="no"
diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am
index 35a5457..a3bc9e0 100644
--- a/lib/go/test/Makefile.am
+++ b/lib/go/test/Makefile.am
@@ -17,8 +17,12 @@
# under the License.
#
+if GOVERSION_LT_17
+COMPILER_EXTRAFLAG=",legacy_context"
+endif
+
THRIFT = $(top_builddir)/compiler/cpp/thrift
-THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift,legacy_context
+THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
# Thrift for GO has problems with complex map keys: THRIFT-2063
diff --git a/lib/go/test/tests/client_error_test.go b/lib/go/test/tests/client_error_test.go
index 0810be6..ad43447 100644
--- a/lib/go/test/tests/client_error_test.go
+++ b/lib/go/test/tests/client_error_test.go
@@ -412,7 +412,7 @@
return
}
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
- _, retErr := client.TestStruct(thing)
+ _, retErr := client.TestStruct(defaultCtx, thing)
mockCtrl.Finish()
err2, ok := retErr.(thrift.TTransportException)
if !ok {
@@ -444,7 +444,7 @@
return
}
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
- _, retErr := client.TestStruct(thing)
+ _, retErr := client.TestStruct(defaultCtx, thing)
mockCtrl.Finish()
err2, ok := retErr.(thrift.TProtocolException)
if !ok {
@@ -565,7 +565,7 @@
willComplete := !prepareClientCallException(protocol, i, err)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
- _, retErr := client.TestString("test")
+ _, retErr := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
if !willComplete {
@@ -608,7 +608,7 @@
)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
- _, err := client.TestString("test")
+ _, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
@@ -638,7 +638,7 @@
)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
- _, err := client.TestString("test")
+ _, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
@@ -668,7 +668,7 @@
)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
- _, err := client.TestString("test")
+ _, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
diff --git a/lib/go/test/tests/multiplexed_protocol_test.go b/lib/go/test/tests/multiplexed_protocol_test.go
index ccf7b30..27802e5 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -103,7 +103,7 @@
}
func TestCallFirst(t *testing.T) {
- ret, err := firstClient.ReturnOne()
+ ret, err := firstClient.ReturnOne(defaultCtx)
if err != nil {
t.Fatal("Unable to call first server:", err)
}
@@ -113,7 +113,7 @@
}
func TestCallSecond(t *testing.T) {
- ret, err := secondClient.ReturnTwo()
+ ret, err := secondClient.ReturnTwo(defaultCtx)
if err != nil {
t.Fatal("Unable to call second server:", err)
}
@@ -124,7 +124,7 @@
func TestCallLegacy(t *testing.T) {
legacyClient := createLegacyClient(t)
- ret, err := legacyClient.ReturnTwo()
+ ret, err := legacyClient.ReturnTwo(defaultCtx)
//expect error since default processor is not registered
if err == nil {
t.Fatal("Expecting error")
@@ -132,7 +132,7 @@
//register default processor and call again
processor.RegisterDefault(multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{}))
legacyClient = createLegacyClient(t)
- ret, err = legacyClient.ReturnTwo()
+ ret, err = legacyClient.ReturnTwo(defaultCtx)
if err != nil {
t.Fatal("Unable to call legacy server:", err)
}
diff --git a/lib/go/test/tests/one_way_test.go b/lib/go/test/tests/one_way_test.go
index d7519a2..32881e2 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -68,12 +68,12 @@
func TestCallOnewayServer(t *testing.T) {
//call oneway function
- err := client.Hi(1, "")
+ err := client.Hi(defaultCtx, 1, "")
if err != nil {
t.Fatal("Unexpected error: ", err)
}
//There is no way to detect protocol problems with single oneway call so we call it second time
- i, err := client.EchoInt(42)
+ i, err := client.EchoInt(defaultCtx, 42)
if err != nil {
t.Fatal("Unexpected error: ", err)
}
diff --git a/lib/go/test/tests/thrifttest_driver.go b/lib/go/test/tests/thrifttest_driver.go
index f8643ed..de54cbc 100644
--- a/lib/go/test/tests/thrifttest_driver.go
+++ b/lib/go/test/tests/thrifttest_driver.go
@@ -26,11 +26,11 @@
)
type ThriftTestDriver struct {
- client *thrifttest.ThriftTestClient
+ client thrifttest.ThriftTest
t *testing.T
}
-func NewThriftTestDriver(t *testing.T, client *thrifttest.ThriftTestClient) *ThriftTestDriver {
+func NewThriftTestDriver(t *testing.T, client thrifttest.ThriftTest) *ThriftTestDriver {
return &ThriftTestDriver{client, t}
}
@@ -38,15 +38,15 @@
client := p.client
t := p.t
- if client.TestVoid() != nil {
+ if client.TestVoid(defaultCtx) != nil {
t.Fatal("TestVoid failed")
}
- if r, err := client.TestString("Test"); r != "Test" || err != nil {
+ if r, err := client.TestString(defaultCtx, "Test"); r != "Test" || err != nil {
t.Fatal("TestString with simple text failed")
}
- if r, err := client.TestString(""); r != "" || err != nil {
+ if r, err := client.TestString(defaultCtx, ""); r != "" || err != nil {
t.Fatal("TestString with empty text failed")
}
@@ -76,7 +76,7 @@
"Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +
"Bân-lâm-gú, 粵語"
- if r, err := client.TestString(stringTest); r != stringTest || err != nil {
+ if r, err := client.TestString(defaultCtx, stringTest); r != stringTest || err != nil {
t.Fatal("TestString with all languages failed")
}
@@ -86,44 +86,44 @@
" now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" +
" char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ "
- if r, err := client.TestString(specialCharacters); r != specialCharacters || err != nil {
+ if r, err := client.TestString(defaultCtx, specialCharacters); r != specialCharacters || err != nil {
t.Fatal("TestString with specialCharacters failed")
}
- if r, err := client.TestByte(1); r != 1 || err != nil {
+ if r, err := client.TestByte(defaultCtx, 1); r != 1 || err != nil {
t.Fatal("TestByte(1) failed")
}
- if r, err := client.TestByte(0); r != 0 || err != nil {
+ if r, err := client.TestByte(defaultCtx, 0); r != 0 || err != nil {
t.Fatal("TestByte(0) failed")
}
- if r, err := client.TestByte(-1); r != -1 || err != nil {
+ if r, err := client.TestByte(defaultCtx, -1); r != -1 || err != nil {
t.Fatal("TestByte(-1) failed")
}
- if r, err := client.TestByte(-127); r != -127 || err != nil {
+ if r, err := client.TestByte(defaultCtx, -127); r != -127 || err != nil {
t.Fatal("TestByte(-127) failed")
}
- if r, err := client.TestI32(-1); r != -1 || err != nil {
+ if r, err := client.TestI32(defaultCtx, -1); r != -1 || err != nil {
t.Fatal("TestI32(-1) failed")
}
- if r, err := client.TestI32(1); r != 1 || err != nil {
+ if r, err := client.TestI32(defaultCtx, 1); r != 1 || err != nil {
t.Fatal("TestI32(1) failed")
}
- if r, err := client.TestI64(-5); r != -5 || err != nil {
+ if r, err := client.TestI64(defaultCtx, -5); r != -5 || err != nil {
t.Fatal("TestI64(-5) failed")
}
- if r, err := client.TestI64(5); r != 5 || err != nil {
+ if r, err := client.TestI64(defaultCtx, 5); r != 5 || err != nil {
t.Fatal("TestI64(5) failed")
}
- if r, err := client.TestI64(-34359738368); r != -34359738368 || err != nil {
+ if r, err := client.TestI64(defaultCtx, -34359738368); r != -34359738368 || err != nil {
t.Fatal("TestI64(-34359738368) failed")
}
- if r, err := client.TestDouble(-5.2098523); r != -5.2098523 || err != nil {
+ if r, err := client.TestDouble(defaultCtx, -5.2098523); r != -5.2098523 || err != nil {
t.Fatal("TestDouble(-5.2098523) failed")
}
- if r, err := client.TestDouble(-7.012052175215044); r != -7.012052175215044 || err != nil {
+ if r, err := client.TestDouble(defaultCtx, -7.012052175215044); r != -7.012052175215044 || err != nil {
t.Fatal("TestDouble(-7.012052175215044) failed")
}
@@ -134,7 +134,7 @@
out.ByteThing = 1
out.I32Thing = -3
out.I64Thing = 1000000
- if r, err := client.TestStruct(out); !reflect.DeepEqual(r, out) || err != nil {
+ if r, err := client.TestStruct(defaultCtx, out); !reflect.DeepEqual(r, out) || err != nil {
t.Fatal("TestStruct failed")
}
@@ -142,7 +142,7 @@
out2.ByteThing = 1
out2.StructThing = out
out2.I32Thing = 5
- if r, err := client.TestNest(out2); !reflect.DeepEqual(r, out2) || err != nil {
+ if r, err := client.TestNest(defaultCtx, out2); !reflect.DeepEqual(r, out2) || err != nil {
t.Fatal("TestNest failed")
}
@@ -150,7 +150,7 @@
for i := int32(0); i < 5; i++ {
mapout[i] = i - 10
}
- if r, err := client.TestMap(mapout); !reflect.DeepEqual(r, mapout) || err != nil {
+ if r, err := client.TestMap(defaultCtx, mapout); !reflect.DeepEqual(r, mapout) || err != nil {
t.Fatal("TestMap failed")
}
@@ -158,25 +158,25 @@
"a": "123", "a b": "with spaces ", "same": "same", "0": "numeric key",
"longValue": stringTest, stringTest: "long key",
}
- if r, err := client.TestStringMap(mapTestInput); !reflect.DeepEqual(r, mapTestInput) || err != nil {
+ if r, err := client.TestStringMap(defaultCtx, mapTestInput); !reflect.DeepEqual(r, mapTestInput) || err != nil {
t.Fatal("TestStringMap failed")
}
setTestInput := []int32{1, 2, 3}
- if r, err := client.TestSet(setTestInput); !reflect.DeepEqual(r, setTestInput) || err != nil {
+ if r, err := client.TestSet(defaultCtx, setTestInput); !reflect.DeepEqual(r, setTestInput) || err != nil {
t.Fatal("TestSet failed")
}
listTest := []int32{1, 2, 3}
- if r, err := client.TestList(listTest); !reflect.DeepEqual(r, listTest) || err != nil {
+ if r, err := client.TestList(defaultCtx, listTest); !reflect.DeepEqual(r, listTest) || err != nil {
t.Fatal("TestList failed")
}
- if r, err := client.TestEnum(thrifttest.Numberz_ONE); r != thrifttest.Numberz_ONE || err != nil {
+ if r, err := client.TestEnum(defaultCtx, thrifttest.Numberz_ONE); r != thrifttest.Numberz_ONE || err != nil {
t.Fatal("TestEnum failed")
}
- if r, err := client.TestTypedef(69); r != 69 || err != nil {
+ if r, err := client.TestTypedef(defaultCtx, 69); r != 69 || err != nil {
t.Fatal("TestTypedef failed")
}
@@ -184,7 +184,7 @@
4: {1: 1, 2: 2, 3: 3, 4: 4},
-4: {-4: -4, -3: -3, -2: -2, -1: -1},
}
- if r, err := client.TestMapMap(1); !reflect.DeepEqual(r, mapMapTest) || err != nil {
+ if r, err := client.TestMapMap(defaultCtx, 1); !reflect.DeepEqual(r, mapMapTest) || err != nil {
t.Fatal("TestMapMap failed")
}
@@ -212,25 +212,25 @@
1: {thrifttest.Numberz_TWO: crazy, thrifttest.Numberz_THREE: crazy},
2: {thrifttest.Numberz_SIX: crazyEmpty},
}
- if r, err := client.TestInsanity(crazy); !reflect.DeepEqual(r, insanity) || err != nil {
+ if r, err := client.TestInsanity(defaultCtx, crazy); !reflect.DeepEqual(r, insanity) || err != nil {
t.Fatal("TestInsanity failed")
}
- if err := client.TestException("TException"); err == nil {
+ if err := client.TestException(defaultCtx, "TException"); err == nil {
t.Fatal("TestException TException failed")
}
- if err, ok := client.TestException("Xception").(*thrifttest.Xception); ok == false || err == nil {
+ if err, ok := client.TestException(defaultCtx, "Xception").(*thrifttest.Xception); ok == false || err == nil {
t.Fatal("TestException Xception failed")
} else if err.ErrorCode != 1001 || err.Message != "Xception" {
t.Fatal("TestException Xception failed")
}
- if err := client.TestException("no Exception"); err != nil {
+ if err := client.TestException(defaultCtx, "no Exception"); err != nil {
t.Fatal("TestException no Exception failed")
}
- if err := client.TestOneway(0); err != nil {
+ if err := client.TestOneway(defaultCtx, 0); err != nil {
t.Fatal("TestOneway failed")
}
}
diff --git a/test/go/Makefile.am b/test/go/Makefile.am
index 4285359..ce711f6 100644
--- a/test/go/Makefile.am
+++ b/test/go/Makefile.am
@@ -18,9 +18,12 @@
#
BUILT_SOURCES = gopath
+if GOVERSION_LT_17
+COMPILER_EXTRAFLAG=",legacy_context"
+endif
THRIFT = $(top_builddir)/compiler/cpp/thrift
-THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift,legacy_context
+THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
precross: bin/testclient bin/testserver
@@ -52,7 +55,7 @@
check_PROGRAMS: bin/testclient bin/testserver bin/stress
-check: gopath
+check: gopath genmock
GOPATH=`pwd` $(GO) test -v common/...
genmock: gopath
diff --git a/test/go/src/bin/testclient/go17.go b/test/go/src/bin/testclient/go17.go
new file mode 100644
index 0000000..a6003a9
--- /dev/null
+++ b/test/go/src/bin/testclient/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/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 228120b..b34c539 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -63,11 +63,11 @@
func callEverything(client *thrifttest.ThriftTestClient) {
var err error
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Fatalf("Unexpected error in TestVoid() call: ", err)
}
- thing, err := client.TestString("thing")
+ thing, err := client.TestString(defaultCtx, "thing")
if err != nil {
t.Fatalf("Unexpected error in TestString() call: ", err)
}
@@ -75,14 +75,14 @@
t.Fatalf("Unexpected TestString() result, expected 'thing' got '%s' ", thing)
}
- bl, err := client.TestBool(true)
+ bl, err := client.TestBool(defaultCtx, true)
if err != nil {
t.Fatalf("Unexpected error in TestBool() call: ", err)
}
if !bl {
t.Fatalf("Unexpected TestBool() result expected true, got %f ", bl)
}
- bl, err = client.TestBool(false)
+ bl, err = client.TestBool(defaultCtx, false)
if err != nil {
t.Fatalf("Unexpected error in TestBool() call: ", err)
}
@@ -90,7 +90,7 @@
t.Fatalf("Unexpected TestBool() result expected false, got %f ", bl)
}
- b, err := client.TestByte(42)
+ b, err := client.TestByte(defaultCtx, 42)
if err != nil {
t.Fatalf("Unexpected error in TestByte() call: ", err)
}
@@ -98,7 +98,7 @@
t.Fatalf("Unexpected TestByte() result expected 42, got %d ", b)
}
- i32, err := client.TestI32(4242)
+ i32, err := client.TestI32(defaultCtx, 4242)
if err != nil {
t.Fatalf("Unexpected error in TestI32() call: ", err)
}
@@ -106,7 +106,7 @@
t.Fatalf("Unexpected TestI32() result expected 4242, got %d ", i32)
}
- i64, err := client.TestI64(424242)
+ i64, err := client.TestI64(defaultCtx, 424242)
if err != nil {
t.Fatalf("Unexpected error in TestI64() call: ", err)
}
@@ -114,7 +114,7 @@
t.Fatalf("Unexpected TestI64() result expected 424242, got %d ", i64)
}
- d, err := client.TestDouble(42.42)
+ d, err := client.TestDouble(defaultCtx, 42.42)
if err != nil {
t.Fatalf("Unexpected error in TestDouble() call: ", err)
}
@@ -126,19 +126,19 @@
for i := 0; i < 256; i++ {
binout[i] = byte(i)
}
- bin, err := client.TestBinary(binout)
+ bin, err := client.TestBinary(defaultCtx, binout)
for i := 0; i < 256; i++ {
if (binout[i] != bin[i]) {
t.Fatalf("Unexpected TestBinary() result expected %d, got %d ", binout[i], bin[i])
}
}
-
+
xs := thrifttest.NewXtruct()
xs.StringThing = "thing"
xs.ByteThing = 42
xs.I32Thing = 4242
xs.I64Thing = 424242
- xsret, err := client.TestStruct(xs)
+ xsret, err := client.TestStruct(defaultCtx, xs)
if err != nil {
t.Fatalf("Unexpected error in TestStruct() call: ", err)
}
@@ -148,7 +148,7 @@
x2 := thrifttest.NewXtruct2()
x2.StructThing = xs
- x2ret, err := client.TestNest(x2)
+ x2ret, err := client.TestNest(defaultCtx, x2)
if err != nil {
t.Fatalf("Unexpected error in TestNest() call: ", err)
}
@@ -157,7 +157,7 @@
}
m := map[int32]int32{1: 2, 3: 4, 5: 42}
- mret, err := client.TestMap(m)
+ mret, err := client.TestMap(defaultCtx, m)
if err != nil {
t.Fatalf("Unexpected error in TestMap() call: ", err)
}
@@ -166,7 +166,7 @@
}
sm := map[string]string{"a": "2", "b": "blah", "some": "thing"}
- smret, err := client.TestStringMap(sm)
+ smret, err := client.TestStringMap(defaultCtx, sm)
if err != nil {
t.Fatalf("Unexpected error in TestStringMap() call: ", err)
}
@@ -175,7 +175,7 @@
}
s := []int32{1, 2, 42}
- sret, err := client.TestSet(s)
+ sret, err := client.TestSet(defaultCtx, s)
if err != nil {
t.Fatalf("Unexpected error in TestSet() call: ", err)
}
@@ -191,7 +191,7 @@
}
l := []int32{1, 2, 42}
- lret, err := client.TestList(l)
+ lret, err := client.TestList(defaultCtx, l)
if err != nil {
t.Fatalf("Unexpected error in TestList() call: ", err)
}
@@ -199,7 +199,7 @@
t.Fatalf("Unexpected TestList() result expected %#v, got %#v ", l, lret)
}
- eret, err := client.TestEnum(thrifttest.Numberz_TWO)
+ eret, err := client.TestEnum(defaultCtx, thrifttest.Numberz_TWO)
if err != nil {
t.Fatalf("Unexpected error in TestEnum() call: ", err)
}
@@ -207,7 +207,7 @@
t.Fatalf("Unexpected TestEnum() result expected %#v, got %#v ", thrifttest.Numberz_TWO, eret)
}
- tret, err := client.TestTypedef(thrifttest.UserId(42))
+ tret, err := client.TestTypedef(defaultCtx, thrifttest.UserId(42))
if err != nil {
t.Fatalf("Unexpected error in TestTypedef() call: ", err)
}
@@ -215,7 +215,7 @@
t.Fatalf("Unexpected TestTypedef() result expected %#v, got %#v ", thrifttest.UserId(42), tret)
}
- mapmap, err := client.TestMapMap(42)
+ mapmap, err := client.TestMapMap(defaultCtx, 42)
if err != nil {
t.Fatalf("Unexpected error in TestMapMap() call: ", err)
}
@@ -242,7 +242,7 @@
truck1,
truck2,
}
- insanity, err := client.TestInsanity(crazy)
+ insanity, err := client.TestInsanity(defaultCtx, crazy)
if err != nil {
t.Fatalf("Unexpected error in TestInsanity() call: ", err)
}
@@ -261,7 +261,7 @@
insanity[2][6])
}
- xxsret, err := client.TestMulti(42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
+ xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
if err != nil {
t.Fatalf("Unexpected error in TestMulti() call: ", err)
}
@@ -269,7 +269,7 @@
t.Fatalf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
}
- err = client.TestException("Xception")
+ err = client.TestException(defaultCtx, "Xception")
if err == nil {
t.Fatalf("Expecting exception in TestException() call")
}
@@ -277,13 +277,13 @@
t.Fatalf("Unexpected TestException() result expected %#v, got %#v ", xcept, err)
}
- err = client.TestException("TException")
+ err = client.TestException(defaultCtx, "TException")
_, ok := err.(thrift.TApplicationException)
if err == nil || !ok {
t.Fatalf("Unexpected TestException() result expected ApplicationError, got %#v ", err)
}
- ign, err := client.TestMultiException("Xception", "ignoreme")
+ ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme")
if ign != nil || err == nil {
t.Fatalf("Expecting exception in TestMultiException() call")
}
@@ -291,7 +291,7 @@
t.Fatalf("Unexpected TestMultiException() %#v ", err)
}
- ign, err = client.TestMultiException("Xception2", "ignoreme")
+ ign, err = client.TestMultiException(defaultCtx, "Xception2", "ignoreme")
if ign != nil || err == nil {
t.Fatalf("Expecting exception in TestMultiException() call")
}
@@ -301,13 +301,13 @@
t.Fatalf("Unexpected TestMultiException() %#v ", err)
}
- err = client.TestOneway(2)
+ err = client.TestOneway(defaultCtx, 2)
if err != nil {
t.Fatalf("Unexpected error in TestOneway() call: ", err)
}
//Make sure the connection still alive
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Fatalf("Unexpected error in TestVoid() call: ", err)
}
}
diff --git a/test/go/src/bin/testclient/pre_go17.go b/test/go/src/bin/testclient/pre_go17.go
new file mode 100644
index 0000000..10a6fb8
--- /dev/null
+++ b/test/go/src/bin/testclient/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()
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index acc3dba..ecd021f 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -120,11 +120,11 @@
handler.EXPECT().TestVoid(gomock.Any()),
)
var err error
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Errorf("Unexpected error in TestVoid() call: ", err)
}
- thing, err := client.TestString("thing")
+ thing, err := client.TestString(defaultCtx, "thing")
if err != nil {
t.Errorf("Unexpected error in TestString() call: ", err)
}
@@ -132,14 +132,14 @@
t.Errorf("Unexpected TestString() result, expected 'thing' got '%s' ", thing)
}
- bl, err := client.TestBool(true)
+ bl, err := client.TestBool(defaultCtx, true)
if err != nil {
t.Errorf("Unexpected error in TestBool() call: ", err)
}
if !bl {
t.Errorf("Unexpected TestBool() result expected true, got %f ", bl)
}
- bl, err = client.TestBool(false)
+ bl, err = client.TestBool(defaultCtx, false)
if err != nil {
t.Errorf("Unexpected error in TestBool() call: ", err)
}
@@ -147,7 +147,7 @@
t.Errorf("Unexpected TestBool() result expected false, got %f ", bl)
}
- b, err := client.TestByte(42)
+ b, err := client.TestByte(defaultCtx, 42)
if err != nil {
t.Errorf("Unexpected error in TestByte() call: ", err)
}
@@ -155,7 +155,7 @@
t.Errorf("Unexpected TestByte() result expected 42, got %d ", b)
}
- i32, err := client.TestI32(4242)
+ i32, err := client.TestI32(defaultCtx, 4242)
if err != nil {
t.Errorf("Unexpected error in TestI32() call: ", err)
}
@@ -163,7 +163,7 @@
t.Errorf("Unexpected TestI32() result expected 4242, got %d ", i32)
}
- i64, err := client.TestI64(424242)
+ i64, err := client.TestI64(defaultCtx, 424242)
if err != nil {
t.Errorf("Unexpected error in TestI64() call: ", err)
}
@@ -171,7 +171,7 @@
t.Errorf("Unexpected TestI64() result expected 424242, got %d ", i64)
}
- d, err := client.TestDouble(42.42)
+ d, err := client.TestDouble(defaultCtx, 42.42)
if err != nil {
t.Errorf("Unexpected error in TestDouble() call: ", err)
}
@@ -186,7 +186,7 @@
xs.ByteThing = 42
xs.I32Thing = 4242
xs.I64Thing = 424242
- xsret, err := client.TestStruct(xs)
+ xsret, err := client.TestStruct(defaultCtx, xs)
if err != nil {
t.Errorf("Unexpected error in TestStruct() call: ", err)
}
@@ -196,7 +196,7 @@
x2 := thrifttest.NewXtruct2()
x2.StructThing = xs
- x2ret, err := client.TestNest(x2)
+ x2ret, err := client.TestNest(defaultCtx, x2)
if err != nil {
t.Errorf("Unexpected error in TestNest() call: ", err)
}
@@ -205,7 +205,7 @@
}
m := map[int32]int32{1: 2, 3: 4, 5: 42}
- mret, err := client.TestMap(m)
+ mret, err := client.TestMap(defaultCtx, m)
if err != nil {
t.Errorf("Unexpected error in TestMap() call: ", err)
}
@@ -214,7 +214,7 @@
}
sm := map[string]string{"a": "2", "b": "blah", "some": "thing"}
- smret, err := client.TestStringMap(sm)
+ smret, err := client.TestStringMap(defaultCtx, sm)
if err != nil {
t.Errorf("Unexpected error in TestStringMap() call: ", err)
}
@@ -223,7 +223,7 @@
}
s := []int32{1, 2, 42}
- sret, err := client.TestSet(s)
+ sret, err := client.TestSet(defaultCtx, s)
if err != nil {
t.Errorf("Unexpected error in TestSet() call: ", err)
}
@@ -239,7 +239,7 @@
}
l := []int32{1, 2, 42}
- lret, err := client.TestList(l)
+ lret, err := client.TestList(defaultCtx, l)
if err != nil {
t.Errorf("Unexpected error in TestList() call: ", err)
}
@@ -247,7 +247,7 @@
t.Errorf("Unexpected TestList() result expected %#v, got %#v ", l, lret)
}
- eret, err := client.TestEnum(thrifttest.Numberz_TWO)
+ eret, err := client.TestEnum(defaultCtx, thrifttest.Numberz_TWO)
if err != nil {
t.Errorf("Unexpected error in TestEnum() call: ", err)
}
@@ -255,7 +255,7 @@
t.Errorf("Unexpected TestEnum() result expected %#v, got %#v ", thrifttest.Numberz_TWO, eret)
}
- tret, err := client.TestTypedef(thrifttest.UserId(42))
+ tret, err := client.TestTypedef(defaultCtx, thrifttest.UserId(42))
if err != nil {
t.Errorf("Unexpected error in TestTypedef() call: ", err)
}
@@ -263,7 +263,7 @@
t.Errorf("Unexpected TestTypedef() result expected %#v, got %#v ", thrifttest.UserId(42), tret)
}
- mapmap, err := client.TestMapMap(42)
+ mapmap, err := client.TestMapMap(defaultCtx, 42)
if err != nil {
t.Errorf("Unexpected error in TestMapmap() call: ", err)
}
@@ -271,7 +271,7 @@
t.Errorf("Unexpected TestMapmap() result expected %#v, got %#v ", rmapmap, mapmap)
}
- xxsret, err := client.TestMulti(42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
+ xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
if err != nil {
t.Errorf("Unexpected error in TestMulti() call: ", err)
}
@@ -279,7 +279,7 @@
t.Errorf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
}
- err = client.TestException("some")
+ err = client.TestException(defaultCtx, "some")
if err == nil {
t.Errorf("Expecting exception in TestException() call")
}
@@ -288,13 +288,13 @@
}
// TODO: connection is being closed on this
- err = client.TestException("TException")
+ err = client.TestException(defaultCtx, "TException")
tex, ok := err.(thrift.TApplicationException)
if err == nil || !ok || tex.TypeId() != thrift.INTERNAL_ERROR {
t.Errorf("Unexpected TestException() result expected ApplicationError, got %#v ", err)
}
- ign, err := client.TestMultiException("Xception", "ignoreme")
+ ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme")
if ign != nil || err == nil {
t.Errorf("Expecting exception in TestMultiException() call")
}
@@ -302,7 +302,7 @@
t.Errorf("Unexpected TestMultiException() %#v ", err)
}
- ign, err = client.TestMultiException("Xception2", "ignoreme")
+ ign, err = client.TestMultiException(defaultCtx, "Xception2", "ignoreme")
if ign != nil || err == nil {
t.Errorf("Expecting exception in TestMultiException() call")
}
@@ -312,13 +312,13 @@
t.Errorf("Unexpected TestMultiException() %#v ", err)
}
- err = client.TestOneway(2)
+ err = client.TestOneway(defaultCtx, 2)
if err != nil {
t.Errorf("Unexpected error in TestOneway() call: ", err)
}
//Make sure the connection still alive
- if err = client.TestVoid(); err != nil {
+ if err = client.TestVoid(defaultCtx); err != nil {
t.Errorf("Unexpected error in TestVoid() call: ", err)
}
}
diff --git a/test/go/src/common/go17.go b/test/go/src/common/go17.go
new file mode 100644
index 0000000..9aca407
--- /dev/null
+++ b/test/go/src/common/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 common
+
+import "context"
+
+var defaultCtx = context.Background()
diff --git a/test/go/src/common/pre_go17.go b/test/go/src/common/pre_go17.go
new file mode 100644
index 0000000..6c14579
--- /dev/null
+++ b/test/go/src/common/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 common
+
+import "golang.org/x/net/context"
+
+var defaultCtx = context.Background()
diff --git a/tutorial/go/Makefile.am b/tutorial/go/Makefile.am
index c328d38..b6ad9a5 100644
--- a/tutorial/go/Makefile.am
+++ b/tutorial/go/Makefile.am
@@ -17,15 +17,19 @@
# under the License.
#
+if GOVERSION_LT_17
+COMPILER_EXTRAFLAG=":legacy_context"
+endif
+
THRIFT = $(top_builddir)/compiler/cpp/thrift
gen-go/tutorial/calculator.go gen-go/shared/shared_service.go: $(top_srcdir)/tutorial/tutorial.thrift
- $(THRIFT) --gen go:legacy_context -r $<
+ $(THRIFT) --gen go$(COMPILER_EXTRAFLAG) -r $<
all-local: gen-go/tutorial/calculator.go
check: src/git.apache.org/thrift.git/lib/go/thrift thirdparty-dep
- $(THRIFT) -r --gen go:legacy_context $(top_srcdir)/tutorial/tutorial.thrift
+ $(THRIFT) -r --gen go$(COMPILER_EXTRAFLAG) $(top_srcdir)/tutorial/tutorial.thrift
cp -r gen-go/* src/
GOPATH=`pwd` $(GO) build -o go-tutorial ./src
GOPATH=`pwd` $(GO) build -o calculator-remote src/tutorial/calculator-remote/calculator-remote.go
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()