You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jk...@apache.org on 2018/03/13 02:30:24 UTC
[2/5] thrift git commit: THRIFT-4448: Golang: do something with
context.Context. Remove Go1.6 compatibility. Client: go
THRIFT-4448: Golang: do something with context.Context. Remove Go1.6 compatibility.
Client: go
This closes #1459
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/5785279e
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/5785279e
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/5785279e
Branch: refs/heads/master
Commit: 5785279e2e809f6c56dbbe0eb41d13fb17c88bdd
Parents: 3ae3042
Author: John Boiles <jo...@gmail.com>
Authored: Fri Jan 5 14:37:05 2018 -0800
Committer: James E. King III <jk...@apache.org>
Committed: Mon Mar 12 18:35:17 2018 -0400
----------------------------------------------------------------------
LANGUAGES.md | 2 +-
build/docker/README.md | 4 +-
build/docker/ubuntu-artful/Dockerfile | 14 +-
build/docker/ubuntu-trusty/Dockerfile | 12 +-
build/docker/ubuntu-xenial/Dockerfile | 17 +-
.../cpp/src/thrift/generate/t_go_generator.cc | 27 +-
.../generate/thrift-t_php_generator.o-a60a38e9 | 0
lib/go/Makefile.am | 2 -
lib/go/README.md | 2 +
lib/go/test/Makefile.am | 5 -
lib/go/test/tests/client_error_test.go | 17 +-
lib/go/test/tests/context.go | 26 ++
lib/go/test/tests/go17.go | 47 ---
lib/go/test/tests/multiplexed_protocol_test.go | 13 +
lib/go/test/tests/one_way_test.go | 8 +
lib/go/test/tests/pre_go17.go | 48 ---
lib/go/test/tests/protocol_mock.go | 5 +-
lib/go/test/tests/thrifttest_handler.go | 5 +-
lib/go/test/tests/thrifttest_handler_go17.go | 212 ----------
lib/go/thrift/binary_protocol.go | 5 +-
lib/go/thrift/buffered_transport.go | 5 +-
lib/go/thrift/client.go | 17 +-
lib/go/thrift/client_go17.go | 13 -
lib/go/thrift/client_pre_go17.go | 13 -
lib/go/thrift/common_test.go | 30 ++
lib/go/thrift/common_test_go17.go | 32 --
lib/go/thrift/common_test_pre_go17.go | 32 --
lib/go/thrift/compact_protocol.go | 5 +-
lib/go/thrift/context.go | 24 ++
lib/go/thrift/debug_protocol.go | 5 +-
lib/go/thrift/framed_transport.go | 5 +-
lib/go/thrift/go17.go | 26 --
lib/go/thrift/http_client.go | 6 +-
lib/go/thrift/http_transport.go | 12 +
lib/go/thrift/http_transport_go17.go | 38 --
lib/go/thrift/http_transport_pre_go17.go | 40 --
lib/go/thrift/iostream_transport.go | 3 +-
lib/go/thrift/json_protocol.go | 5 +-
lib/go/thrift/json_protocol_test.go | 39 +-
lib/go/thrift/memory_buffer.go | 3 +-
lib/go/thrift/multiplexed_protocol.go | 31 ++
lib/go/thrift/multiplexed_protocol_go17.go | 53 ---
lib/go/thrift/multiplexed_protocol_pre_go17.go | 54 ---
lib/go/thrift/pre_go17.go | 26 --
lib/go/thrift/processor.go | 34 --
lib/go/thrift/processor_factory.go | 12 +
lib/go/thrift/processor_go17.go | 34 --
lib/go/thrift/protocol.go | 3 +-
lib/go/thrift/protocol_test.go | 17 +-
lib/go/thrift/serializer.go | 16 +-
lib/go/thrift/serializer_test.go | 5 +-
lib/go/thrift/simple_json_protocol.go | 3 +-
lib/go/thrift/simple_json_protocol_test.go | 47 +--
lib/go/thrift/socket.go | 3 +-
lib/go/thrift/ssl_socket.go | 3 +-
lib/go/thrift/transport.go | 9 +-
lib/go/thrift/transport_test.go | 7 +-
lib/go/thrift/zlib_transport.go | 5 +-
test/go/Makefile.am | 4 -
test/go/src/bin/stress/go17.go | 62 ---
test/go/src/bin/stress/main.go | 36 ++
test/go/src/bin/stress/pre_go17.go | 63 ---
test/go/src/bin/testclient/go17.go | 26 --
test/go/src/bin/testclient/main.go | 2 +
test/go/src/bin/testclient/pre_go17.go | 26 --
test/go/src/common/clientserver_test.go | 2 +
test/go/src/common/context_test.go | 98 +++++
test/go/src/common/go17.go | 26 --
test/go/src/common/pre_go17.go | 26 --
test/go/src/common/printing_handler.go | 11 +-
test/go/src/common/printing_handler_go17.go | 386 -------------------
tutorial/go/Makefile.am | 10 -
tutorial/go/src/client.go | 3 +
tutorial/go/src/go17.go | 26 --
tutorial/go/src/handler.go | 5 +-
tutorial/go/src/handler_go17.go | 104 -----
tutorial/go/src/pre_go17.go | 26 --
77 files changed, 483 insertions(+), 1645 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/LANGUAGES.md
----------------------------------------------------------------------
diff --git a/LANGUAGES.md b/LANGUAGES.md
index c99c457..205a47b 100644
--- a/LANGUAGES.md
+++ b/LANGUAGES.md
@@ -156,7 +156,7 @@ The Language/Library Levels indicate the minimum and maximum versions that are u
<td align=left><a href="lib/go/README.md">Go</a></td>
<!-- Since -----------------><td>0.7.0</td>
<!-- Build Systems ---------><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cred.png" alt=""/></td>
-<!-- Language Levels -------><td>1.6.2</td><td>1.8.3</td>
+<!-- Language Levels -------><td>1.7.6</td><td>1.9.4</td>
<!-- Low-Level Transports --><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td>
<!-- Transport Wrappers ----><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td>
<!-- Protocols -------------><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td>
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/build/docker/README.md
----------------------------------------------------------------------
diff --git a/build/docker/README.md b/build/docker/README.md
index d7a0126..c2b203b 100644
--- a/build/docker/README.md
+++ b/build/docker/README.md
@@ -148,7 +148,7 @@ Last updated: October 1, 2017
| delphi | | | Not in CI |
| dotnet | 2.1.4 | 2.1.4 | v2.1.4 SDK uses v2.0.5 Runtime |
| erlang | 18.3 | 20.0.4 | |
-| go | 1.6.2 | 1.8.3 | |
+| go | 1.7.6 | 1.9.4 | THRIFT-4516: avoid 1.10 |
| haskell | 7.10.3 | 8.0.2 | |
| haxe | 3.2.1 | 3.4.4 | THRIFT-4352: avoid 3.4.2 |
| java | 1.8.0_151 | 1.8.0_151 | |
@@ -164,5 +164,3 @@ Last updated: October 1, 2017
| rust | 1.17.0 | 1.21.0 | |
| smalltalk | | | Not in CI |
| swift | | | Not in CI |
-
-
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/build/docker/ubuntu-artful/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/ubuntu-artful/Dockerfile b/build/docker/ubuntu-artful/Dockerfile
index 416d75e..dacaa28 100644
--- a/build/docker/ubuntu-artful/Dockerfile
+++ b/build/docker/ubuntu-artful/Dockerfile
@@ -18,6 +18,7 @@
# - dart: does not come with Ubuntu
# - dotnet: does not come with Ubuntu
# - haxe: version 3.4.2 that comes with Ubuntu cores in our CI build
+# - go: xenial comes with 1.8, we want the latest (supported)
# - nodejs: want v8, Ubuntu comes with v6
#
@@ -140,10 +141,15 @@ RUN apt-get install -y --no-install-recommends \
`# GlibC dependencies` \
libglib2.0-dev
-RUN apt-get install -y --no-install-recommends \
-`# golang (go) dependencies` \
- golang-go \
- golang-race-detector-runtime
+# golang
+ENV GOLANG_VERSION 1.9.4
+ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
+ENV GOLANG_DOWNLOAD_SHA256 15b0937615809f87321a457bb1265f946f9f6e736c563d6c5e0bd2c22e44f779
+RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz && \
+ echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - && \
+ tar -C /usr/local -xzf golang.tar.gz && \
+ ln -s /usr/local/go/bin/go /usr/local/bin && \
+ rm golang.tar.gz
RUN apt-get install -y --no-install-recommends \
`# Haskell dependencies` \
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/build/docker/ubuntu-trusty/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/ubuntu-trusty/Dockerfile b/build/docker/ubuntu-trusty/Dockerfile
index 40f9c55..a8e4d3b 100644
--- a/build/docker/ubuntu-trusty/Dockerfile
+++ b/build/docker/ubuntu-trusty/Dockerfile
@@ -113,9 +113,15 @@ RUN apt-get install -y --no-install-recommends \
`# GlibC dependencies` \
libglib2.0-dev
-RUN apt-get install -y --no-install-recommends \
-`# golang (go) dependencies` \
- golang-go
+# golang
+ENV GOLANG_VERSION 1.7.6
+ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
+ENV GOLANG_DOWNLOAD_SHA256 ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea
+RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz && \
+ echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - && \
+ tar -C /usr/local -xzf golang.tar.gz && \
+ ln -s /usr/local/go/bin/go /usr/local/bin && \
+ rm golang.tar.gz
RUN apt-get install -y --no-install-recommends \
`# Haskell dependencies` \
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/build/docker/ubuntu-xenial/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/ubuntu-xenial/Dockerfile b/build/docker/ubuntu-xenial/Dockerfile
index b69d7ea..832542e 100644
--- a/build/docker/ubuntu-xenial/Dockerfile
+++ b/build/docker/ubuntu-xenial/Dockerfile
@@ -15,7 +15,9 @@
# Using all stock Ubuntu Xenial packaging except for:
# - d: does not come with Ubuntu so we're installing 2.073.2 for coverage
# - dart: does not come with Ubuntu so we're installing 1.22.1 for coverage
-# - nodejs: Ubuntu comes with 4.2.6 which exits LTS April 2018, so we're installing 6.x
+# - dotnet: does not come with Ubuntu
+# - go: Xenial comes with 1.6, but we need 1.7 or later
+# - nodejs: Xenial comes with 4.2.6 which exits LTS April 2018, so we're installing 6.x
#
FROM buildpack-deps:xenial-scm
@@ -138,10 +140,15 @@ RUN apt-get install -y --no-install-recommends \
`# GlibC dependencies` \
libglib2.0-dev
-RUN apt-get install -y --no-install-recommends \
-`# golang (go) dependencies` \
- golang-go \
- golang-race-detector-runtime
+# golang
+ENV GOLANG_VERSION 1.7.6
+ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
+ENV GOLANG_DOWNLOAD_SHA256 ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea
+RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz && \
+ echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - && \
+ tar -C /usr/local -xzf golang.tar.gz && \
+ ln -s /usr/local/go/bin/go /usr/local/bin && \
+ rm golang.tar.gz
RUN apt-get install -y --no-install-recommends \
`# Haskell dependencies` \
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/compiler/cpp/src/thrift/generate/t_go_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index 60481fb..28725ac 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -81,7 +81,6 @@ public:
gen_package_prefix_ = "";
package_flag = "";
read_write_private_ = false;
- legacy_context_ = false;
ignore_initialisms_ = false;
for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
if( iter->first.compare("package_prefix") == 0) {
@@ -92,8 +91,6 @@ public:
package_flag = (iter->second);
} else if( iter->first.compare("read_write_private") == 0) {
read_write_private_ = true;
- } else if( iter->first.compare("legacy_context") == 0) {
- legacy_context_ = true;
} else if( iter->first.compare("ignore_initialisms") == 0) {
ignore_initialisms_ = true;
} else {
@@ -287,7 +284,6 @@ private:
std::string gen_package_prefix_;
std::string gen_thrift_import_;
bool read_write_private_;
- bool legacy_context_;
bool ignore_initialisms_;
/**
@@ -875,16 +871,10 @@ string t_go_generator::go_imports_begin(bool consts) {
"\t\"database/sql/driver\"\n"
"\t\"errors\"\n";
}
- if (legacy_context_) {
- extra +=
- "\t\"golang.org/x/net/context\"\n";
- } else {
- extra +=
- "\t\"context\"\n";
- }
return string(
"import (\n"
"\t\"bytes\"\n"
+ "\t\"context\"\n"
"\t\"reflect\"\n"
+ extra +
"\t\"fmt\"\n"
@@ -2073,9 +2063,6 @@ void t_go_generator::generate_service_remote(t_service* tservice) {
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;
@@ -2602,7 +2589,7 @@ void t_go_generator::generate_service_server(t_service* tservice) {
f_types_ << indent() << " oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)" << endl;
f_types_ << indent() << " " << x << ".Write(oprot)" << endl;
f_types_ << indent() << " oprot.WriteMessageEnd()" << endl;
- f_types_ << indent() << " oprot.Flush()" << endl;
+ f_types_ << indent() << " oprot.Flush(ctx)" << endl;
f_types_ << indent() << " return false, " << x << endl;
f_types_ << indent() << "" << endl;
f_types_ << indent() << "}" << endl << endl;
@@ -2667,7 +2654,7 @@ void t_go_generator::generate_process_function(t_service* tservice, t_function*
<< "\", thrift.EXCEPTION, seqId)" << endl;
f_types_ << indent() << " x.Write(oprot)" << endl;
f_types_ << indent() << " oprot.WriteMessageEnd()" << endl;
- f_types_ << indent() << " oprot.Flush()" << endl;
+ f_types_ << indent() << " oprot.Flush(ctx)" << endl;
}
f_types_ << indent() << " return false, err" << endl;
f_types_ << indent() << "}" << endl << endl;
@@ -2735,7 +2722,7 @@ void t_go_generator::generate_process_function(t_service* tservice, t_function*
<< "\", thrift.EXCEPTION, seqId)" << endl;
f_types_ << indent() << " x.Write(oprot)" << endl;
f_types_ << indent() << " oprot.WriteMessageEnd()" << endl;
- f_types_ << indent() << " oprot.Flush()" << endl;
+ f_types_ << indent() << " oprot.Flush(ctx)" << endl;
}
f_types_ << indent() << " return true, err2" << endl;
@@ -2772,7 +2759,7 @@ void t_go_generator::generate_process_function(t_service* tservice, t_function*
<< endl;
f_types_ << indent() << " err = err2" << endl;
f_types_ << indent() << "}" << endl;
- f_types_ << indent() << "if err2 = oprot.Flush(); err == nil && err2 != nil {" << endl;
+ f_types_ << indent() << "if err2 = oprot.Flush(ctx); err == nil && err2 != nil {" << endl;
f_types_ << indent() << " err = err2" << endl;
f_types_ << indent() << "}" << endl;
f_types_ << indent() << "if err != nil {" << endl;
@@ -3668,6 +3655,4 @@ THRIFT_REGISTER_GENERATOR(go, "Go",
" ignore_initialisms\n"
" Disable automatic spelling correction of initialisms (e.g. \"URL\")\n" \
" read_write_private\n"
- " Make read/write methods private, default is public Read/Write\n" \
- " legacy_context\n"
- " Use legacy x/net/context instead of context in go<1.7.\n")
+ " Make read/write methods private, default is public Read/Write\n")
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/compiler/cpp/src/thrift/generate/thrift-t_php_generator.o-a60a38e9
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thrift/generate/thrift-t_php_generator.o-a60a38e9 b/compiler/cpp/src/thrift/generate/thrift-t_php_generator.o-a60a38e9
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/go/Makefile.am b/lib/go/Makefile.am
index 0d59710..0dfa5fa 100644
--- a/lib/go/Makefile.am
+++ b/lib/go/Makefile.am
@@ -31,14 +31,12 @@ install:
@echo '##############################################################'
check-local:
- GOPATH=`pwd` $(GO) get golang.org/x/net/context
GOPATH=`pwd` $(GO) test -race ./thrift
clean-local:
$(RM) -rf pkg
all-local:
- GOPATH=`pwd` $(GO) get golang.org/x/net/context
GOPATH=`pwd` $(GO) build ./thrift
EXTRA_DIST = \
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/README.md
----------------------------------------------------------------------
diff --git a/lib/go/README.md b/lib/go/README.md
index 7440474..debc9ac 100644
--- a/lib/go/README.md
+++ b/lib/go/README.md
@@ -24,6 +24,8 @@ under the License.
Using Thrift with Go
====================
+Thrift supports Go 1.7+
+
In following Go conventions, we recommend you use the 'go' tool to install
Thrift for go.
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am
index 842f2de..e93ec5c 100644
--- a/lib/go/test/Makefile.am
+++ b/lib/go/test/Makefile.am
@@ -17,10 +17,6 @@
# under the License.
#
-if GOVERSION_LT_17
-COMPILER_EXTRAFLAG=",legacy_context"
-endif
-
THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
@@ -59,7 +55,6 @@ gopath: $(THRIFT) $(THRIFTTEST) \
$(THRIFT) $(THRIFTARGS) InitialismsTest.thrift
$(THRIFT) $(THRIFTARGS),read_write_private DontExportRWTest.thrift
$(THRIFT) $(THRIFTARGS),ignore_initialisms IgnoreInitialismsTest.thrift
- GOPATH=`pwd`/gopath $(GO) get golang.org/x/net/context
GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock || true
sed -i 's/\"context\"/\"golang.org\/x\/net\/context\"/g' gopath/src/github.com/golang/mock/gomock/controller.go || true
GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/client_error_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/client_error_test.go b/lib/go/test/tests/client_error_test.go
index 5dec472..fdec4ea 100644
--- a/lib/go/test/tests/client_error_test.go
+++ b/lib/go/test/tests/client_error_test.go
@@ -20,6 +20,7 @@
package tests
import (
+ "context"
"errors"
"errortest"
"testing"
@@ -212,7 +213,7 @@ func prepareClientCallReply(protocol *MockTProtocol, failAt int, failWith error)
if failAt == 25 {
err = failWith
}
- last = protocol.EXPECT().Flush().Return(err).After(last)
+ last = protocol.EXPECT().Flush(context.Background()).Return(err).After(last)
if failAt == 25 {
return true
}
@@ -536,7 +537,7 @@ func prepareClientCallException(protocol *MockTProtocol, failAt int, failWith er
last = protocol.EXPECT().WriteFieldStop().After(last)
last = protocol.EXPECT().WriteStructEnd().After(last)
last = protocol.EXPECT().WriteMessageEnd().After(last)
- last = protocol.EXPECT().Flush().After(last)
+ last = protocol.EXPECT().Flush(context.Background()).After(last)
// Reading the exception, might fail.
if failAt == 0 {
@@ -704,7 +705,7 @@ func TestClientSeqIdMismatch(t *testing.T) {
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
)
@@ -735,7 +736,7 @@ func TestClientSeqIdMismatchLegeacy(t *testing.T) {
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
)
@@ -764,7 +765,7 @@ func TestClientWrongMethodName(t *testing.T) {
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
)
@@ -795,7 +796,7 @@ func TestClientWrongMethodNameLegacy(t *testing.T) {
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
)
@@ -824,7 +825,7 @@ func TestClientWrongMessageType(t *testing.T) {
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
)
@@ -855,7 +856,7 @@ func TestClientWrongMessageTypeLegacy(t *testing.T) {
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
)
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/context.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/context.go b/lib/go/test/tests/context.go
new file mode 100644
index 0000000..a93a82b
--- /dev/null
+++ b/lib/go/test/tests/context.go
@@ -0,0 +1,26 @@
+/*
+ * 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 tests
+
+import (
+ "context"
+)
+
+var defaultCtx = context.Background()
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/go17.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/go17.go b/lib/go/test/tests/go17.go
deleted file mode 100644
index dc3c9d5..0000000
--- a/lib/go/test/tests/go17.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// +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 tests
-
-import (
- "context"
- "fmt"
-)
-
-var defaultCtx = context.Background()
-
-type FirstImpl struct{}
-
-func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
- return 1, nil
-}
-
-type SecondImpl struct{}
-
-func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
- return 2, nil
-}
-
-type impl struct{}
-
-func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
-func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
-func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/multiplexed_protocol_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/multiplexed_protocol_test.go b/lib/go/test/tests/multiplexed_protocol_test.go
index 0b5896b..61ac628 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -20,6 +20,7 @@
package tests
import (
+ "context"
"multiplexedprotocoltest"
"net"
"testing"
@@ -36,6 +37,18 @@ func FindAvailableTCPServerPort() net.Addr {
}
}
+type FirstImpl struct{}
+
+func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
+ return 1, nil
+}
+
+type SecondImpl struct{}
+
+func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
+ return 2, nil
+}
+
func createTransport(addr net.Addr) (thrift.TTransport, error) {
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport := thrift.NewTFramedTransport(socket)
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/one_way_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/one_way_test.go b/lib/go/test/tests/one_way_test.go
index 8abd671..48d0bbe 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -20,6 +20,8 @@
package tests
import (
+ "context"
+ "fmt"
"net"
"onewaytest"
"testing"
@@ -36,6 +38,12 @@ func findPort() net.Addr {
}
}
+type impl struct{}
+
+func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
+func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
+func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
+
const TIMEOUT = time.Second
var addr net.Addr
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/pre_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/pre_go17.go b/lib/go/test/tests/pre_go17.go
deleted file mode 100644
index 8ab4331..0000000
--- a/lib/go/test/tests/pre_go17.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// +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 tests
-
-import (
- "fmt"
-
- "golang.org/x/net/context"
-)
-
-var defaultCtx = context.Background()
-
-type FirstImpl struct{}
-
-func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
- return 1, nil
-}
-
-type SecondImpl struct{}
-
-func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
- return 2, nil
-}
-
-type impl struct{}
-
-func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
-func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
-func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/protocol_mock.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/protocol_mock.go b/lib/go/test/tests/protocol_mock.go
index 8476c86..51d7a02 100644
--- a/lib/go/test/tests/protocol_mock.go
+++ b/lib/go/test/tests/protocol_mock.go
@@ -23,6 +23,7 @@
package tests
import (
+ "context"
thrift "thrift"
gomock "github.com/golang/mock/gomock"
@@ -49,13 +50,13 @@ func (_m *MockTProtocol) EXPECT() *_MockTProtocolRecorder {
return _m.recorder
}
-func (_m *MockTProtocol) Flush() error {
+func (_m *MockTProtocol) Flush(ctx context.Context) error {
ret := _m.ctrl.Call(_m, "Flush")
ret0, _ := ret[0].(error)
return ret0
}
-func (_mr *_MockTProtocolRecorder) Flush() *gomock.Call {
+func (_mr *_MockTProtocolRecorder) Flush(ctx context.Context) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Flush")
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/thrifttest_handler.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/thrifttest_handler.go b/lib/go/test/tests/thrifttest_handler.go
index 6542fac..31b9ee2 100644
--- a/lib/go/test/tests/thrifttest_handler.go
+++ b/lib/go/test/tests/thrifttest_handler.go
@@ -1,5 +1,3 @@
-// +build !go1.7
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,12 +20,11 @@
package tests
import (
+ "context"
"errors"
"thrift"
"thrifttest"
"time"
-
- "golang.org/x/net/context"
)
type SecondServiceHandler struct {
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/test/tests/thrifttest_handler_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/thrifttest_handler_go17.go b/lib/go/test/tests/thrifttest_handler_go17.go
deleted file mode 100644
index e022a3d..0000000
--- a/lib/go/test/tests/thrifttest_handler_go17.go
+++ /dev/null
@@ -1,212 +0,0 @@
-// +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 tests
-
-import (
- "context"
- "errors"
- "thrift"
- "thrifttest"
- "time"
-)
-
-type SecondServiceHandler struct {
-}
-
-func NewSecondServiceHandler() *SecondServiceHandler {
- return &SecondServiceHandler{}
-}
-
-func (p *SecondServiceHandler) BlahBlah(ctx context.Context) (err error) {
- return nil
-}
-
-func (p *SecondServiceHandler) SecondtestString(ctx context.Context, thing string) (r string, err error) {
- return thing, nil
-}
-
-type ThriftTestHandler struct {
-}
-
-func NewThriftTestHandler() *ThriftTestHandler {
- return &ThriftTestHandler{}
-}
-
-func (p *ThriftTestHandler) TestVoid(ctx context.Context) (err error) {
- return nil
-}
-
-func (p *ThriftTestHandler) TestString(ctx context.Context, thing string) (r string, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestStruct(ctx context.Context, thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestNest(ctx context.Context, thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestEnum(ctx context.Context, thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestTypedef(ctx context.Context, thing thrifttest.UserId) (r thrifttest.UserId, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) {
- r = make(map[int32]map[int32]int32)
- pos := make(map[int32]int32)
- neg := make(map[int32]int32)
-
- for i := int32(1); i < 5; i++ {
- pos[i] = i
- neg[-i] = -i
- }
- r[4] = pos
- r[-4] = neg
-
- return r, nil
-}
-
-func (p *ThriftTestHandler) TestInsanity(ctx context.Context, argument *thrifttest.Insanity) (r map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, err error) {
- hello := thrifttest.NewXtruct()
- hello.StringThing = "Hello2"
- hello.ByteThing = 2
- hello.I32Thing = 2
- hello.I64Thing = 2
-
- goodbye := thrifttest.NewXtruct()
- goodbye.StringThing = "Goodbye4"
- goodbye.ByteThing = 4
- goodbye.I32Thing = 4
- goodbye.I64Thing = 4
-
- crazy := thrifttest.NewInsanity()
- crazy.UserMap = make(map[thrifttest.Numberz]thrifttest.UserId)
- crazy.UserMap[thrifttest.Numberz_EIGHT] = 8
- crazy.UserMap[thrifttest.Numberz_FIVE] = 5
- crazy.Xtructs = []*thrifttest.Xtruct{goodbye, hello}
-
- first_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
- second_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
-
- first_map[thrifttest.Numberz_TWO] = crazy
- first_map[thrifttest.Numberz_THREE] = crazy
-
- looney := thrifttest.NewInsanity()
- second_map[thrifttest.Numberz_SIX] = looney
-
- var insane = make(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
- insane[1] = first_map
- insane[2] = second_map
-
- return insane, nil
-}
-
-func (p *ThriftTestHandler) TestMulti(ctx context.Context, arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 thrifttest.Numberz, arg5 thrifttest.UserId) (r *thrifttest.Xtruct, err error) {
- r = thrifttest.NewXtruct()
- r.StringThing = "Hello2"
- r.ByteThing = arg0
- r.I32Thing = arg1
- r.I64Thing = arg2
- return r, nil
-}
-
-func (p *ThriftTestHandler) TestException(ctx context.Context, arg string) (err error) {
- if arg == "Xception" {
- x := thrifttest.NewXception()
- x.ErrorCode = 1001
- x.Message = arg
- return x
- } else if arg == "TException" {
- return thrift.TException(errors.New(arg))
- } else {
- return nil
- }
-}
-
-func (p *ThriftTestHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
- if arg0 == "Xception" {
- x := thrifttest.NewXception()
- x.ErrorCode = 1001
- x.Message = "This is an Xception"
- return nil, x
- } else if arg0 == "Xception2" {
- x2 := thrifttest.NewXception2()
- x2.ErrorCode = 2002
- x2.StructThing = thrifttest.NewXtruct()
- x2.StructThing.StringThing = "This is an Xception2"
- return nil, x2
- }
-
- res := thrifttest.NewXtruct()
- res.StringThing = arg1
- return res, nil
-}
-
-func (p *ThriftTestHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
- time.Sleep(time.Second * time.Duration(secondsToSleep))
- return nil
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/binary_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/binary_protocol.go b/lib/go/thrift/binary_protocol.go
index 690d341..de0f6a7 100644
--- a/lib/go/thrift/binary_protocol.go
+++ b/lib/go/thrift/binary_protocol.go
@@ -21,6 +21,7 @@ package thrift
import (
"bytes"
+ "context"
"encoding/binary"
"errors"
"fmt"
@@ -457,8 +458,8 @@ func (p *TBinaryProtocol) ReadBinary() ([]byte, error) {
return buf, NewTProtocolException(err)
}
-func (p *TBinaryProtocol) Flush() (err error) {
- return NewTProtocolException(p.trans.Flush())
+func (p *TBinaryProtocol) Flush(ctx context.Context) (err error) {
+ return NewTProtocolException(p.trans.Flush(ctx))
}
func (p *TBinaryProtocol) Skip(fieldType TType) (err error) {
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/buffered_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/buffered_transport.go b/lib/go/thrift/buffered_transport.go
index b754f92..9670206 100644
--- a/lib/go/thrift/buffered_transport.go
+++ b/lib/go/thrift/buffered_transport.go
@@ -21,6 +21,7 @@ package thrift
import (
"bufio"
+ "context"
)
type TBufferedTransportFactory struct {
@@ -78,12 +79,12 @@ func (p *TBufferedTransport) Write(b []byte) (int, error) {
return n, err
}
-func (p *TBufferedTransport) Flush() error {
+func (p *TBufferedTransport) Flush(ctx context.Context) error {
if err := p.ReadWriter.Flush(); err != nil {
p.ReadWriter.Writer.Reset(p.tp)
return err
}
- return p.tp.Flush()
+ return p.tp.Flush(ctx)
}
func (p *TBufferedTransport) RemainingBytes() (num_bytes uint64) {
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/client.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/client.go b/lib/go/thrift/client.go
index 8bdb53d..28791cc 100644
--- a/lib/go/thrift/client.go
+++ b/lib/go/thrift/client.go
@@ -1,6 +1,13 @@
package thrift
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
+
+type TClient interface {
+ Call(ctx context.Context, method string, args, result TStruct) error
+}
type TStandardClient struct {
seqId int32
@@ -16,7 +23,7 @@ func NewTStandardClient(inputProtocol, outputProtocol TProtocol) *TStandardClien
}
}
-func (p *TStandardClient) Send(oprot TProtocol, seqId int32, method string, args TStruct) error {
+func (p *TStandardClient) Send(ctx context.Context, oprot TProtocol, seqId int32, method string, args TStruct) error {
if err := oprot.WriteMessageBegin(method, CALL, seqId); err != nil {
return err
}
@@ -26,7 +33,7 @@ func (p *TStandardClient) Send(oprot TProtocol, seqId int32, method string, args
if err := oprot.WriteMessageEnd(); err != nil {
return err
}
- return oprot.Flush()
+ return oprot.Flush(ctx)
}
func (p *TStandardClient) Recv(iprot TProtocol, seqId int32, method string, result TStruct) error {
@@ -61,11 +68,11 @@ func (p *TStandardClient) Recv(iprot TProtocol, seqId int32, method string, resu
return iprot.ReadMessageEnd()
}
-func (p *TStandardClient) call(method string, args, result TStruct) error {
+func (p *TStandardClient) Call(ctx context.Context, method string, args, result TStruct) error {
p.seqId++
seqId := p.seqId
- if err := p.Send(p.oprot, seqId, method, args); err != nil {
+ if err := p.Send(ctx, p.oprot, seqId, method, args); err != nil {
return err
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/client_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/client_go17.go b/lib/go/thrift/client_go17.go
deleted file mode 100644
index 15c1c52..0000000
--- a/lib/go/thrift/client_go17.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// +build go1.7
-
-package thrift
-
-import "context"
-
-type TClient interface {
- Call(ctx context.Context, method string, args, result TStruct) error
-}
-
-func (p *TStandardClient) Call(ctx context.Context, method string, args, result TStruct) error {
- return p.call(method, args, result)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/client_pre_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/client_pre_go17.go b/lib/go/thrift/client_pre_go17.go
deleted file mode 100644
index d2e99ef..0000000
--- a/lib/go/thrift/client_pre_go17.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// +build !go1.7
-
-package thrift
-
-import "golang.org/x/net/context"
-
-type TClient interface {
- Call(ctx context.Context, method string, args, result TStruct) error
-}
-
-func (p *TStandardClient) Call(ctx context.Context, method string, args, result TStruct) error {
- return p.call(method, args, result)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/common_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/common_test.go b/lib/go/thrift/common_test.go
new file mode 100644
index 0000000..93597ff
--- /dev/null
+++ b/lib/go/thrift/common_test.go
@@ -0,0 +1,30 @@
+/*
+ * 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 thrift
+
+import "context"
+
+type mockProcessor struct {
+ ProcessFunc func(in, out TProtocol) (bool, TException)
+}
+
+func (m *mockProcessor) Process(ctx context.Context, in, out TProtocol) (bool, TException) {
+ return m.ProcessFunc(in, out)
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/common_test_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/common_test_go17.go b/lib/go/thrift/common_test_go17.go
deleted file mode 100644
index 2c729a2..0000000
--- a/lib/go/thrift/common_test_go17.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// +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 thrift
-
-import "context"
-
-type mockProcessor struct {
- ProcessFunc func(in, out TProtocol) (bool, TException)
-}
-
-func (m *mockProcessor) Process(ctx context.Context, in, out TProtocol) (bool, TException) {
- return m.ProcessFunc(in, out)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/common_test_pre_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/common_test_pre_go17.go b/lib/go/thrift/common_test_pre_go17.go
deleted file mode 100644
index e6d0c4d..0000000
--- a/lib/go/thrift/common_test_pre_go17.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// +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 thrift
-
-import "golang.org/x/net/context"
-
-type mockProcessor struct {
- ProcessFunc func(in, out TProtocol) (bool, TException)
-}
-
-func (m *mockProcessor) Process(ctx context.Context, in, out TProtocol) (bool, TException) {
- return m.ProcessFunc(in, out)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/compact_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/compact_protocol.go b/lib/go/thrift/compact_protocol.go
index 0bc5fdd..fc1d182 100644
--- a/lib/go/thrift/compact_protocol.go
+++ b/lib/go/thrift/compact_protocol.go
@@ -20,6 +20,7 @@
package thrift
import (
+ "context"
"encoding/binary"
"fmt"
"io"
@@ -599,8 +600,8 @@ func (p *TCompactProtocol) ReadBinary() (value []byte, err error) {
return buf, NewTProtocolException(e)
}
-func (p *TCompactProtocol) Flush() (err error) {
- return NewTProtocolException(p.trans.Flush())
+func (p *TCompactProtocol) Flush(ctx context.Context) (err error) {
+ return NewTProtocolException(p.trans.Flush(ctx))
}
func (p *TCompactProtocol) Skip(fieldType TType) (err error) {
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/context.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/context.go b/lib/go/thrift/context.go
new file mode 100644
index 0000000..d15c1bc
--- /dev/null
+++ b/lib/go/thrift/context.go
@@ -0,0 +1,24 @@
+/*
+ * 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 thrift
+
+import "context"
+
+var defaultCtx = context.Background()
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/debug_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/debug_protocol.go b/lib/go/thrift/debug_protocol.go
index d37252c..57943e0 100644
--- a/lib/go/thrift/debug_protocol.go
+++ b/lib/go/thrift/debug_protocol.go
@@ -20,6 +20,7 @@
package thrift
import (
+ "context"
"log"
)
@@ -258,8 +259,8 @@ func (tdp *TDebugProtocol) Skip(fieldType TType) (err error) {
log.Printf("%sSkip(fieldType=%#v) (err=%#v)", tdp.LogPrefix, fieldType, err)
return
}
-func (tdp *TDebugProtocol) Flush() (err error) {
- err = tdp.Delegate.Flush()
+func (tdp *TDebugProtocol) Flush(ctx context.Context) (err error) {
+ err = tdp.Delegate.Flush(ctx)
log.Printf("%sFlush() (err=%#v)", tdp.LogPrefix, err)
return
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/framed_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/framed_transport.go b/lib/go/thrift/framed_transport.go
index 60b1249..81fa65a 100644
--- a/lib/go/thrift/framed_transport.go
+++ b/lib/go/thrift/framed_transport.go
@@ -22,6 +22,7 @@ package thrift
import (
"bufio"
"bytes"
+ "context"
"encoding/binary"
"fmt"
"io"
@@ -135,7 +136,7 @@ func (p *TFramedTransport) WriteString(s string) (n int, err error) {
return p.buf.WriteString(s)
}
-func (p *TFramedTransport) Flush() error {
+func (p *TFramedTransport) Flush(ctx context.Context) error {
size := p.buf.Len()
buf := p.buffer[:4]
binary.BigEndian.PutUint32(buf, uint32(size))
@@ -151,7 +152,7 @@ func (p *TFramedTransport) Flush() error {
return NewTTransportExceptionFromError(err)
}
}
- err = p.transport.Flush()
+ err = p.transport.Flush(ctx)
return NewTTransportExceptionFromError(err)
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/go17.go b/lib/go/thrift/go17.go
deleted file mode 100644
index e3b21c4..0000000
--- a/lib/go/thrift/go17.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// +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 thrift
-
-import "context"
-
-var defaultCtx = context.Background()
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/http_client.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/http_client.go b/lib/go/thrift/http_client.go
index 33f2aa4..5c82bf5 100644
--- a/lib/go/thrift/http_client.go
+++ b/lib/go/thrift/http_client.go
@@ -21,6 +21,7 @@ package thrift
import (
"bytes"
+ "context"
"io"
"io/ioutil"
"net/http"
@@ -181,7 +182,7 @@ func (p *THttpClient) WriteString(s string) (n int, err error) {
return p.requestBuffer.WriteString(s)
}
-func (p *THttpClient) Flush() error {
+func (p *THttpClient) Flush(ctx context.Context) error {
// Close any previous response body to avoid leaking connections.
p.closeResponse()
@@ -190,6 +191,9 @@ func (p *THttpClient) Flush() error {
return NewTTransportExceptionFromError(err)
}
req.Header = p.header
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
response, err := p.client.Do(req)
if err != nil {
return NewTTransportExceptionFromError(err)
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/http_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/http_transport.go b/lib/go/thrift/http_transport.go
index 601855b..66f0f38 100644
--- a/lib/go/thrift/http_transport.go
+++ b/lib/go/thrift/http_transport.go
@@ -26,6 +26,18 @@ import (
"strings"
)
+// NewThriftHandlerFunc is a function that create a ready to use Apache Thrift Handler function
+func NewThriftHandlerFunc(processor TProcessor,
+ inPfactory, outPfactory TProtocolFactory) func(w http.ResponseWriter, r *http.Request) {
+
+ return gz(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Add("Content-Type", "application/x-thrift")
+
+ transport := NewStreamTransport(r.Body, w)
+ processor.Process(r.Context(), inPfactory.GetProtocol(transport), outPfactory.GetProtocol(transport))
+ })
+}
+
// gz transparently compresses the HTTP response if the client supports it.
func gz(handler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/http_transport_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/http_transport_go17.go b/lib/go/thrift/http_transport_go17.go
deleted file mode 100644
index 1313ac2..0000000
--- a/lib/go/thrift/http_transport_go17.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// +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 thrift
-
-import (
- "net/http"
-)
-
-// NewThriftHandlerFunc is a function that create a ready to use Apache Thrift Handler function
-func NewThriftHandlerFunc(processor TProcessor,
- inPfactory, outPfactory TProtocolFactory) func(w http.ResponseWriter, r *http.Request) {
-
- return gz(func(w http.ResponseWriter, r *http.Request) {
- w.Header().Add("Content-Type", "application/x-thrift")
-
- transport := NewStreamTransport(r.Body, w)
- processor.Process(r.Context(), inPfactory.GetProtocol(transport), outPfactory.GetProtocol(transport))
- })
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/http_transport_pre_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/http_transport_pre_go17.go b/lib/go/thrift/http_transport_pre_go17.go
deleted file mode 100644
index 13aa1c1..0000000
--- a/lib/go/thrift/http_transport_pre_go17.go
+++ /dev/null
@@ -1,40 +0,0 @@
-// +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 thrift
-
-import (
- "net/http"
-
- "golang.org/x/net/context"
-)
-
-// NewThriftHandlerFunc is a function that create a ready to use Apache Thrift Handler function
-func NewThriftHandlerFunc(processor TProcessor,
- inPfactory, outPfactory TProtocolFactory) func(w http.ResponseWriter, r *http.Request) {
-
- return gz(func(w http.ResponseWriter, r *http.Request) {
- w.Header().Add("Content-Type", "application/x-thrift")
-
- transport := NewStreamTransport(r.Body, w)
- processor.Process(context.Background(), inPfactory.GetProtocol(transport), outPfactory.GetProtocol(transport))
- })
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/iostream_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/iostream_transport.go b/lib/go/thrift/iostream_transport.go
index b18be81..fea93bc 100644
--- a/lib/go/thrift/iostream_transport.go
+++ b/lib/go/thrift/iostream_transport.go
@@ -21,6 +21,7 @@ package thrift
import (
"bufio"
+ "context"
"io"
)
@@ -138,7 +139,7 @@ func (p *StreamTransport) Close() error {
}
// Flushes the underlying output stream if not null.
-func (p *StreamTransport) Flush() error {
+func (p *StreamTransport) Flush(ctx context.Context) error {
if p.Writer == nil {
return NewTTransportException(NOT_OPEN, "Cannot flush null outputStream")
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/json_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/json_protocol.go b/lib/go/thrift/json_protocol.go
index 442fa91..7be685d 100644
--- a/lib/go/thrift/json_protocol.go
+++ b/lib/go/thrift/json_protocol.go
@@ -20,6 +20,7 @@
package thrift
import (
+ "context"
"encoding/base64"
"fmt"
)
@@ -438,10 +439,10 @@ func (p *TJSONProtocol) ReadBinary() ([]byte, error) {
return v, p.ParsePostValue()
}
-func (p *TJSONProtocol) Flush() (err error) {
+func (p *TJSONProtocol) Flush(ctx context.Context) (err error) {
err = p.writer.Flush()
if err == nil {
- err = p.trans.Flush()
+ err = p.trans.Flush(ctx)
}
return NewTProtocolException(err)
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/json_protocol_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/json_protocol_test.go b/lib/go/thrift/json_protocol_test.go
index 7104ce3..0902f1b 100644
--- a/lib/go/thrift/json_protocol_test.go
+++ b/lib/go/thrift/json_protocol_test.go
@@ -20,6 +20,7 @@
package thrift
import (
+ "context"
"encoding/base64"
"encoding/json"
"fmt"
@@ -36,7 +37,7 @@ func TestWriteJSONProtocolBool(t *testing.T) {
if e := p.WriteBool(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -68,7 +69,7 @@ func TestReadJSONProtocolBool(t *testing.T) {
} else {
trans.Write([]byte{'0'}) // not JSON_FALSE
}
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadBool()
if e != nil {
@@ -94,7 +95,7 @@ func TestWriteJSONProtocolByte(t *testing.T) {
if e := p.WriteByte(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -116,7 +117,7 @@ func TestReadJSONProtocolByte(t *testing.T) {
trans := NewTMemoryBuffer()
p := NewTJSONProtocol(trans)
trans.WriteString(strconv.Itoa(int(value)))
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadByte()
if e != nil {
@@ -141,7 +142,7 @@ func TestWriteJSONProtocolI16(t *testing.T) {
if e := p.WriteI16(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -163,7 +164,7 @@ func TestReadJSONProtocolI16(t *testing.T) {
trans := NewTMemoryBuffer()
p := NewTJSONProtocol(trans)
trans.WriteString(strconv.Itoa(int(value)))
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadI16()
if e != nil {
@@ -188,7 +189,7 @@ func TestWriteJSONProtocolI32(t *testing.T) {
if e := p.WriteI32(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -210,7 +211,7 @@ func TestReadJSONProtocolI32(t *testing.T) {
trans := NewTMemoryBuffer()
p := NewTJSONProtocol(trans)
trans.WriteString(strconv.Itoa(int(value)))
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadI32()
if e != nil {
@@ -235,7 +236,7 @@ func TestWriteJSONProtocolI64(t *testing.T) {
if e := p.WriteI64(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -257,7 +258,7 @@ func TestReadJSONProtocolI64(t *testing.T) {
trans := NewTMemoryBuffer()
p := NewTJSONProtocol(trans)
trans.WriteString(strconv.FormatInt(value, 10))
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadI64()
if e != nil {
@@ -282,7 +283,7 @@ func TestWriteJSONProtocolDouble(t *testing.T) {
if e := p.WriteDouble(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -319,7 +320,7 @@ func TestReadJSONProtocolDouble(t *testing.T) {
p := NewTJSONProtocol(trans)
n := NewNumericFromDouble(value)
trans.WriteString(n.String())
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadDouble()
if e != nil {
@@ -358,7 +359,7 @@ func TestWriteJSONProtocolString(t *testing.T) {
if e := p.WriteString(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -380,7 +381,7 @@ func TestReadJSONProtocolString(t *testing.T) {
trans := NewTMemoryBuffer()
p := NewTJSONProtocol(trans)
trans.WriteString(jsonQuote(value))
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadString()
if e != nil {
@@ -409,7 +410,7 @@ func TestWriteJSONProtocolBinary(t *testing.T) {
if e := p.WriteBinary(value); e != nil {
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
}
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
}
s := trans.String()
@@ -441,7 +442,7 @@ func TestReadJSONProtocolBinary(t *testing.T) {
trans := NewTMemoryBuffer()
p := NewTJSONProtocol(trans)
trans.WriteString(jsonQuote(b64String))
- trans.Flush()
+ trans.Flush(context.Background())
s := trans.String()
v, e := p.ReadBinary()
if e != nil {
@@ -474,7 +475,7 @@ func TestWriteJSONProtocolList(t *testing.T) {
}
}
p.WriteListEnd()
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
@@ -528,7 +529,7 @@ func TestWriteJSONProtocolSet(t *testing.T) {
}
}
p.WriteSetEnd()
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
@@ -585,7 +586,7 @@ func TestWriteJSONProtocolMap(t *testing.T) {
}
}
p.WriteMapEnd()
- if e := p.Flush(); e != nil {
+ if e := p.Flush(context.Background()); e != nil {
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
}
str := trans.String()
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/memory_buffer.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/memory_buffer.go b/lib/go/thrift/memory_buffer.go
index 97a4edf..5936d27 100644
--- a/lib/go/thrift/memory_buffer.go
+++ b/lib/go/thrift/memory_buffer.go
@@ -21,6 +21,7 @@ package thrift
import (
"bytes"
+ "context"
)
// Memory buffer-based implementation of the TTransport interface.
@@ -70,7 +71,7 @@ func (p *TMemoryBuffer) Close() error {
}
// Flushing a memory buffer is a no-op
-func (p *TMemoryBuffer) Flush() error {
+func (p *TMemoryBuffer) Flush(ctx context.Context) error {
return nil
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/multiplexed_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/multiplexed_protocol.go b/lib/go/thrift/multiplexed_protocol.go
index b7f4f8a..d028a30 100644
--- a/lib/go/thrift/multiplexed_protocol.go
+++ b/lib/go/thrift/multiplexed_protocol.go
@@ -19,6 +19,12 @@
package thrift
+import (
+ "context"
+ "fmt"
+ "strings"
+)
+
/*
TMultiplexedProtocol is a protocol-independent concrete decorator
that allows a Thrift client to communicate with a multiplexing Thrift server,
@@ -122,6 +128,31 @@ func (t *TMultiplexedProcessor) RegisterProcessor(name string, processor TProces
t.serviceProcessorMap[name] = processor
}
+func (t *TMultiplexedProcessor) Process(ctx context.Context, in, out TProtocol) (bool, TException) {
+ name, typeId, seqid, err := in.ReadMessageBegin()
+ if err != nil {
+ return false, err
+ }
+ if typeId != CALL && typeId != ONEWAY {
+ return false, fmt.Errorf("Unexpected message type %v", typeId)
+ }
+ //extract the service name
+ v := strings.SplitN(name, MULTIPLEXED_SEPARATOR, 2)
+ if len(v) != 2 {
+ if t.DefaultProcessor != nil {
+ smb := NewStoredMessageProtocol(in, name, typeId, seqid)
+ return t.DefaultProcessor.Process(ctx, smb, out)
+ }
+ return false, fmt.Errorf("Service name not found in message name: %s. Did you forget to use a TMultiplexProtocol in your client?", name)
+ }
+ actualProcessor, ok := t.serviceProcessorMap[v[0]]
+ if !ok {
+ return false, fmt.Errorf("Service name not found: %s. Did you forget to call registerProcessor()?", v[0])
+ }
+ smb := NewStoredMessageProtocol(in, v[1], typeId, seqid)
+ return actualProcessor.Process(ctx, smb, out)
+}
+
//Protocol that use stored message for ReadMessageBegin
type storedMessageProtocol struct {
TProtocol
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/multiplexed_protocol_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/multiplexed_protocol_go17.go b/lib/go/thrift/multiplexed_protocol_go17.go
deleted file mode 100644
index c71035e..0000000
--- a/lib/go/thrift/multiplexed_protocol_go17.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// +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 thrift
-
-import (
- "context"
- "fmt"
- "strings"
-)
-
-func (t *TMultiplexedProcessor) Process(ctx context.Context, in, out TProtocol) (bool, TException) {
- name, typeId, seqid, err := in.ReadMessageBegin()
- if err != nil {
- return false, err
- }
- if typeId != CALL && typeId != ONEWAY {
- return false, fmt.Errorf("Unexpected message type %v", typeId)
- }
- //extract the service name
- v := strings.SplitN(name, MULTIPLEXED_SEPARATOR, 2)
- if len(v) != 2 {
- if t.DefaultProcessor != nil {
- smb := NewStoredMessageProtocol(in, name, typeId, seqid)
- return t.DefaultProcessor.Process(ctx, smb, out)
- }
- return false, fmt.Errorf("Service name not found in message name: %s. Did you forget to use a TMultiplexProtocol in your client?", name)
- }
- actualProcessor, ok := t.serviceProcessorMap[v[0]]
- if !ok {
- return false, fmt.Errorf("Service name not found: %s. Did you forget to call registerProcessor()?", v[0])
- }
- smb := NewStoredMessageProtocol(in, v[1], typeId, seqid)
- return actualProcessor.Process(ctx, smb, out)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/multiplexed_protocol_pre_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/multiplexed_protocol_pre_go17.go b/lib/go/thrift/multiplexed_protocol_pre_go17.go
deleted file mode 100644
index 5c27b38..0000000
--- a/lib/go/thrift/multiplexed_protocol_pre_go17.go
+++ /dev/null
@@ -1,54 +0,0 @@
-// +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 thrift
-
-import (
- "fmt"
- "strings"
-
- "golang.org/x/net/context"
-)
-
-func (t *TMultiplexedProcessor) Process(ctx context.Context, in, out TProtocol) (bool, TException) {
- name, typeId, seqid, err := in.ReadMessageBegin()
- if err != nil {
- return false, err
- }
- if typeId != CALL && typeId != ONEWAY {
- return false, fmt.Errorf("Unexpected message type %v", typeId)
- }
- //extract the service name
- v := strings.SplitN(name, MULTIPLEXED_SEPARATOR, 2)
- if len(v) != 2 {
- if t.DefaultProcessor != nil {
- smb := NewStoredMessageProtocol(in, name, typeId, seqid)
- return t.DefaultProcessor.Process(ctx, smb, out)
- }
- return false, fmt.Errorf("Service name not found in message name: %s. Did you forget to use a TMultiplexProtocol in your client?", name)
- }
- actualProcessor, ok := t.serviceProcessorMap[v[0]]
- if !ok {
- return false, fmt.Errorf("Service name not found: %s. Did you forget to call registerProcessor()?", v[0])
- }
- smb := NewStoredMessageProtocol(in, v[1], typeId, seqid)
- return actualProcessor.Process(ctx, smb, out)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/pre_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/pre_go17.go b/lib/go/thrift/pre_go17.go
deleted file mode 100644
index cb564b8..0000000
--- a/lib/go/thrift/pre_go17.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// +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 thrift
-
-import "golang.org/x/net/context"
-
-var defaultCtx = context.Background()
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/processor.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/processor.go b/lib/go/thrift/processor.go
deleted file mode 100644
index 566aaaf..0000000
--- a/lib/go/thrift/processor.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// +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 thrift
-
-import "golang.org/x/net/context"
-
-// A processor is a generic object which operates upon an input stream and
-// writes to some output stream.
-type TProcessor interface {
- Process(ctx context.Context, in, out TProtocol) (bool, TException)
-}
-
-type TProcessorFunction interface {
- Process(ctx context.Context, seqId int32, in, out TProtocol) (bool, TException)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/processor_factory.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/processor_factory.go b/lib/go/thrift/processor_factory.go
index 9d645df..e4b132b 100644
--- a/lib/go/thrift/processor_factory.go
+++ b/lib/go/thrift/processor_factory.go
@@ -19,6 +19,18 @@
package thrift
+import "context"
+
+// A processor is a generic object which operates upon an input stream and
+// writes to some output stream.
+type TProcessor interface {
+ Process(ctx context.Context, in, out TProtocol) (bool, TException)
+}
+
+type TProcessorFunction interface {
+ Process(ctx context.Context, seqId int32, in, out TProtocol) (bool, TException)
+}
+
// The default processor factory just returns a singleton
// instance.
type TProcessorFactory interface {
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/processor_go17.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/processor_go17.go b/lib/go/thrift/processor_go17.go
deleted file mode 100644
index fb0b165..0000000
--- a/lib/go/thrift/processor_go17.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// +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 thrift
-
-import "context"
-
-// A processor is a generic object which operates upon an input stream and
-// writes to some output stream.
-type TProcessor interface {
- Process(ctx context.Context, in, out TProtocol) (bool, TException)
-}
-
-type TProcessorFunction interface {
- Process(ctx context.Context, seqId int32, in, out TProtocol) (bool, TException)
-}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/protocol.go b/lib/go/thrift/protocol.go
index 25e6d24..615b7a4 100644
--- a/lib/go/thrift/protocol.go
+++ b/lib/go/thrift/protocol.go
@@ -20,6 +20,7 @@
package thrift
import (
+ "context"
"errors"
"fmt"
)
@@ -74,7 +75,7 @@ type TProtocol interface {
ReadBinary() (value []byte, err error)
Skip(fieldType TType) (err error)
- Flush() (err error)
+ Flush(ctx context.Context) (err error)
Transport() TTransport
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/protocol_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/protocol_test.go b/lib/go/thrift/protocol_test.go
index 2573312..2e3b65d 100644
--- a/lib/go/thrift/protocol_test.go
+++ b/lib/go/thrift/protocol_test.go
@@ -21,6 +21,7 @@ package thrift
import (
"bytes"
+ "context"
"io/ioutil"
"math"
"net"
@@ -234,7 +235,7 @@ func ReadWriteBool(t testing.TB, p TProtocol, trans TTransport) {
if err != nil {
t.Errorf("%s: %T %T %q Error writing list end: %q", "ReadWriteBool", p, trans, err, BOOL_VALUES)
}
- p.Flush()
+ p.Flush(context.Background())
thetype2, thelen2, err := p.ReadListBegin()
if err != nil {
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteBool", p, trans, err, BOOL_VALUES)
@@ -280,7 +281,7 @@ func ReadWriteByte(t testing.TB, p TProtocol, trans TTransport) {
if err != nil {
t.Errorf("%s: %T %T %q Error writing list end: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
}
- err = p.Flush()
+ err = p.Flush(context.Background())
if err != nil {
t.Errorf("%s: %T %T %q Error flushing list of bytes: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
}
@@ -320,7 +321,7 @@ func ReadWriteI16(t testing.TB, p TProtocol, trans TTransport) {
p.WriteI16(v)
}
p.WriteListEnd()
- p.Flush()
+ p.Flush(context.Background())
thetype2, thelen2, err := p.ReadListBegin()
if err != nil {
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI16", p, trans, err, INT16_VALUES)
@@ -357,7 +358,7 @@ func ReadWriteI32(t testing.TB, p TProtocol, trans TTransport) {
p.WriteI32(v)
}
p.WriteListEnd()
- p.Flush()
+ p.Flush(context.Background())
thetype2, thelen2, err := p.ReadListBegin()
if err != nil {
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI32", p, trans, err, INT32_VALUES)
@@ -393,7 +394,7 @@ func ReadWriteI64(t testing.TB, p TProtocol, trans TTransport) {
p.WriteI64(v)
}
p.WriteListEnd()
- p.Flush()
+ p.Flush(context.Background())
thetype2, thelen2, err := p.ReadListBegin()
if err != nil {
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI64", p, trans, err, INT64_VALUES)
@@ -429,7 +430,7 @@ func ReadWriteDouble(t testing.TB, p TProtocol, trans TTransport) {
p.WriteDouble(v)
}
p.WriteListEnd()
- p.Flush()
+ p.Flush(context.Background())
thetype2, thelen2, err := p.ReadListBegin()
if err != nil {
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteDouble", p, trans, err, DOUBLE_VALUES)
@@ -467,7 +468,7 @@ func ReadWriteString(t testing.TB, p TProtocol, trans TTransport) {
p.WriteString(v)
}
p.WriteListEnd()
- p.Flush()
+ p.Flush(context.Background())
thetype2, thelen2, err := p.ReadListBegin()
if err != nil {
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteString", p, trans, err, STRING_VALUES)
@@ -498,7 +499,7 @@ func ReadWriteString(t testing.TB, p TProtocol, trans TTransport) {
func ReadWriteBinary(t testing.TB, p TProtocol, trans TTransport) {
v := protocol_bdata
p.WriteBinary(v)
- p.Flush()
+ p.Flush(context.Background())
value, err := p.ReadBinary()
if err != nil {
t.Errorf("%s: %T %T Unable to read binary: %s", "ReadWriteBinary", p, trans, err.Error())
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/serializer.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/serializer.go b/lib/go/thrift/serializer.go
index 7712229..1ff4d37 100644
--- a/lib/go/thrift/serializer.go
+++ b/lib/go/thrift/serializer.go
@@ -19,6 +19,10 @@
package thrift
+import (
+ "context"
+)
+
type TSerializer struct {
Transport *TMemoryBuffer
Protocol TProtocol
@@ -38,35 +42,35 @@ func NewTSerializer() *TSerializer {
protocol}
}
-func (t *TSerializer) WriteString(msg TStruct) (s string, err error) {
+func (t *TSerializer) WriteString(ctx context.Context, msg TStruct) (s string, err error) {
t.Transport.Reset()
if err = msg.Write(t.Protocol); err != nil {
return
}
- if err = t.Protocol.Flush(); err != nil {
+ if err = t.Protocol.Flush(ctx); err != nil {
return
}
- if err = t.Transport.Flush(); err != nil {
+ if err = t.Transport.Flush(ctx); err != nil {
return
}
return t.Transport.String(), nil
}
-func (t *TSerializer) Write(msg TStruct) (b []byte, err error) {
+func (t *TSerializer) Write(ctx context.Context, msg TStruct) (b []byte, err error) {
t.Transport.Reset()
if err = msg.Write(t.Protocol); err != nil {
return
}
- if err = t.Protocol.Flush(); err != nil {
+ if err = t.Protocol.Flush(ctx); err != nil {
return
}
- if err = t.Transport.Flush(); err != nil {
+ if err = t.Transport.Flush(ctx); err != nil {
return
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/serializer_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/serializer_test.go b/lib/go/thrift/serializer_test.go
index 06d27a1..32227ef 100644
--- a/lib/go/thrift/serializer_test.go
+++ b/lib/go/thrift/serializer_test.go
@@ -20,6 +20,7 @@
package thrift
import (
+ "context"
"errors"
"fmt"
"testing"
@@ -88,7 +89,7 @@ func ProtocolTest1(test *testing.T, pf ProtocolFactory) (bool, error) {
m.StringSet = make(map[string]struct{}, 5)
m.E = 2
- s, err := t.WriteString(&m)
+ s, err := t.WriteString(context.Background(), &m)
if err != nil {
return false, errors.New(fmt.Sprintf("Unable to Serialize struct\n\t %s", err))
}
@@ -122,7 +123,7 @@ func ProtocolTest2(test *testing.T, pf ProtocolFactory) (bool, error) {
m.StringSet = make(map[string]struct{}, 5)
m.E = 2
- s, err := t.WriteString(&m)
+ s, err := t.WriteString(context.Background(), &m)
if err != nil {
return false, errors.New(fmt.Sprintf("Unable to Serialize struct\n\t %s", err))
http://git-wip-us.apache.org/repos/asf/thrift/blob/5785279e/lib/go/thrift/simple_json_protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/simple_json_protocol.go b/lib/go/thrift/simple_json_protocol.go
index 7353322..88f569c 100644
--- a/lib/go/thrift/simple_json_protocol.go
+++ b/lib/go/thrift/simple_json_protocol.go
@@ -22,6 +22,7 @@ package thrift
import (
"bufio"
"bytes"
+ "context"
"encoding/base64"
"encoding/json"
"fmt"
@@ -552,7 +553,7 @@ func (p *TSimpleJSONProtocol) ReadBinary() ([]byte, error) {
return v, p.ParsePostValue()
}
-func (p *TSimpleJSONProtocol) Flush() (err error) {
+func (p *TSimpleJSONProtocol) Flush(ctx context.Context) (err error) {
return NewTProtocolException(p.writer.Flush())
}