THRIFT-4236 Support context in go generated code
Client: Go
Patch: taozle <zhangliyang26@gmail.com>

This closes #1309
diff --git a/lib/go/Makefile.am b/lib/go/Makefile.am
index b26a890..f1bd0e6 100644
--- a/lib/go/Makefile.am
+++ b/lib/go/Makefile.am
@@ -31,10 +31,12 @@
 	@echo '##############################################################'
 
 check-local:
-	$(GO) test -race ./thrift
+	GOPATH=`pwd` $(GO) get golang.org/x/net/context
+	GOPATH=`pwd` $(GO) test -race ./thrift
 
 all-local:
-	$(GO) build ./thrift
+	GOPATH=`pwd` $(GO) get golang.org/x/net/context
+	GOPATH=`pwd` $(GO) build ./thrift
 
 EXTRA_DIST = \
 	thrift \
diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am
index bbcec96..35a5457 100644
--- a/lib/go/test/Makefile.am
+++ b/lib/go/test/Makefile.am
@@ -18,7 +18,7 @@
 #
 
 THRIFT = $(top_builddir)/compiler/cpp/thrift
-THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift
+THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift,legacy_context
 THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
 
 # Thrift for GO has problems with complex map keys: THRIFT-2063
@@ -57,6 +57,7 @@
 	$(THRIFT) $(THRIFTARGS),read_write_private DontExportRWTest.thrift
 	$(THRIFT) $(THRIFTARGS),ignore_initialisms IgnoreInitialismsTest.thrift
 	GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock
+	GOPATH=`pwd`/gopath $(GO) get golang.org/x/net/context
 	ln -nfs ../../../thrift gopath/src/thrift
 	ln -nfs ../../tests gopath/src/tests
 	cp -r ./dontexportrwtest gopath/src
diff --git a/lib/go/test/tests/go17.go b/lib/go/test/tests/go17.go
new file mode 100644
index 0000000..dc3c9d5
--- /dev/null
+++ b/lib/go/test/tests/go17.go
@@ -0,0 +1,47 @@
+// +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 }
diff --git a/lib/go/test/tests/multiplexed_protocol_test.go b/lib/go/test/tests/multiplexed_protocol_test.go
index b1674bd..ccf7b30 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -36,17 +36,6 @@
 	}
 }
 
-type FirstImpl struct{}
-
-func (f *FirstImpl) ReturnOne() (r int64, err error) {
-	return 1, nil
-}
-
-type SecondImpl struct{}
-
-func (s *SecondImpl) ReturnTwo() (r int64, err error) {
-	return 2, nil
-}
 
 var processor = thrift.NewTMultiplexedProcessor()
 
diff --git a/lib/go/test/tests/one_way_test.go b/lib/go/test/tests/one_way_test.go
index 5bb1dae..d7519a2 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -20,7 +20,6 @@
 package tests
 
 import (
-	"fmt"
 	"net"
 	"onewaytest"
 	"testing"
@@ -37,12 +36,6 @@
 	}
 }
 
-type impl struct{}
-
-func (i *impl) Hi(in int64, s string) (err error)        { fmt.Println("Hi!"); return }
-func (i *impl) Emptyfunc() (err error)                   { return }
-func (i *impl) EchoInt(param int64) (r int64, err error) { return param, nil }
-
 const TIMEOUT = time.Second
 
 var addr net.Addr
diff --git a/lib/go/test/tests/pre_go17.go b/lib/go/test/tests/pre_go17.go
new file mode 100644
index 0000000..8ab4331
--- /dev/null
+++ b/lib/go/test/tests/pre_go17.go
@@ -0,0 +1,48 @@
+// +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 }
diff --git a/lib/go/test/tests/struct_args_rets_test.go b/lib/go/test/tests/struct_args_rets_test.go
index 363423d..81e9b26 100644
--- a/lib/go/test/tests/struct_args_rets_test.go
+++ b/lib/go/test/tests/struct_args_rets_test.go
@@ -30,7 +30,7 @@
 	var iface st.AServ
 	var err error
 
-	sa, err = iface.StructAFunc_1structA(sa)
+	sa, err = iface.StructAFunc_1structA(defaultCtx, sa)
 	_ = err
 	_ = sa
 }
diff --git a/lib/go/test/tests/thrifttest_driver.go b/lib/go/test/tests/thrifttest_driver.go
index a1e6917..f8643ed 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.ThriftTest
+	client *thrifttest.ThriftTestClient
 	t      *testing.T
 }
 
-func NewThriftTestDriver(t *testing.T, client thrifttest.ThriftTest) *ThriftTestDriver {
+func NewThriftTestDriver(t *testing.T, client *thrifttest.ThriftTestClient) *ThriftTestDriver {
 	return &ThriftTestDriver{client, t}
 }
 
diff --git a/lib/go/test/tests/thrifttest_handler.go b/lib/go/test/tests/thrifttest_handler.go
index 5b76066..6542fac 100644
--- a/lib/go/test/tests/thrifttest_handler.go
+++ b/lib/go/test/tests/thrifttest_handler.go
@@ -1,3 +1,5 @@
+// +build !go1.7
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
@@ -24,6 +26,8 @@
 	"thrift"
 	"thrifttest"
 	"time"
+
+	"golang.org/x/net/context"
 )
 
 type SecondServiceHandler struct {
@@ -33,11 +37,11 @@
 	return &SecondServiceHandler{}
 }
 
-func (p *SecondServiceHandler) BlahBlah() (err error) {
+func (p *SecondServiceHandler) BlahBlah(ctx context.Context) (err error) {
 	return nil
 }
 
-func (p *SecondServiceHandler) SecondtestString(thing string) (r string, err error) {
+func (p *SecondServiceHandler) SecondtestString(ctx context.Context, thing string) (r string, err error) {
 	return thing, nil
 }
 
@@ -48,71 +52,71 @@
 	return &ThriftTestHandler{}
 }
 
-func (p *ThriftTestHandler) TestVoid() (err error) {
+func (p *ThriftTestHandler) TestVoid(ctx context.Context) (err error) {
 	return nil
 }
 
-func (p *ThriftTestHandler) TestString(thing string) (r string, err error) {
+func (p *ThriftTestHandler) TestString(ctx context.Context, thing string) (r string, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestBool(thing bool) (r bool, err error) {
+func (p *ThriftTestHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestByte(thing int8) (r int8, err error) {
+func (p *ThriftTestHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestI32(thing int32) (r int32, err error) {
+func (p *ThriftTestHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestI64(thing int64) (r int64, err error) {
+func (p *ThriftTestHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestDouble(thing float64) (r float64, err error) {
+func (p *ThriftTestHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestBinary(thing []byte) (r []byte, err error) {
+func (p *ThriftTestHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestStruct(thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
+func (p *ThriftTestHandler) TestStruct(ctx context.Context, thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestNest(thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
+func (p *ThriftTestHandler) TestNest(ctx context.Context, thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
+func (p *ThriftTestHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
+func (p *ThriftTestHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestSet(thing []int32) (r []int32, err error) {
+func (p *ThriftTestHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestList(thing []int32) (r []int32, err error) {
+func (p *ThriftTestHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestEnum(thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
+func (p *ThriftTestHandler) TestEnum(ctx context.Context, thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestTypedef(thing thrifttest.UserId) (r thrifttest.UserId, err error) {
+func (p *ThriftTestHandler) TestTypedef(ctx context.Context, thing thrifttest.UserId) (r thrifttest.UserId, err error) {
 	return thing, nil
 }
 
-func (p *ThriftTestHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
+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)
@@ -127,7 +131,7 @@
 	return r, nil
 }
 
-func (p *ThriftTestHandler) TestInsanity(argument *thrifttest.Insanity) (r map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, err error) {
+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
@@ -162,7 +166,7 @@
 	return insane, nil
 }
 
-func (p *ThriftTestHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 thrifttest.Numberz, arg5 thrifttest.UserId) (r *thrifttest.Xtruct, err error) {
+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
@@ -171,7 +175,7 @@
 	return r, nil
 }
 
-func (p *ThriftTestHandler) TestException(arg string) (err error) {
+func (p *ThriftTestHandler) TestException(ctx context.Context, arg string) (err error) {
 	if arg == "Xception" {
 		x := thrifttest.NewXception()
 		x.ErrorCode = 1001
@@ -184,7 +188,7 @@
 	}
 }
 
-func (p *ThriftTestHandler) TestMultiException(arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
+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
@@ -203,7 +207,7 @@
 	return res, nil
 }
 
-func (p *ThriftTestHandler) TestOneway(secondsToSleep int32) (err error) {
+func (p *ThriftTestHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
 	time.Sleep(time.Second * time.Duration(secondsToSleep))
 	return nil
 }
diff --git a/lib/go/test/tests/thrifttest_handler_go17.go b/lib/go/test/tests/thrifttest_handler_go17.go
new file mode 100644
index 0000000..e022a3d
--- /dev/null
+++ b/lib/go/test/tests/thrifttest_handler_go17.go
@@ -0,0 +1,212 @@
+// +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
+}
diff --git a/lib/go/thrift/common_test_go17.go b/lib/go/thrift/common_test_go17.go
new file mode 100644
index 0000000..2c729a2
--- /dev/null
+++ b/lib/go/thrift/common_test_go17.go
@@ -0,0 +1,32 @@
+// +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)
+}
diff --git a/lib/go/thrift/common_test_pre_go17.go b/lib/go/thrift/common_test_pre_go17.go
new file mode 100644
index 0000000..e6d0c4d
--- /dev/null
+++ b/lib/go/thrift/common_test_pre_go17.go
@@ -0,0 +1,32 @@
+// +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)
+}
diff --git a/lib/go/thrift/go17.go b/lib/go/thrift/go17.go
new file mode 100644
index 0000000..e3b21c4
--- /dev/null
+++ b/lib/go/thrift/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 thrift
+
+import "context"
+
+var defaultCtx = context.Background()
diff --git a/lib/go/thrift/http_transport.go b/lib/go/thrift/http_transport.go
index d5b5b7c..601855b 100644
--- a/lib/go/thrift/http_transport.go
+++ b/lib/go/thrift/http_transport.go
@@ -21,36 +21,11 @@
 
 import (
 	"compress/gzip"
-	"context"
 	"io"
 	"net/http"
 	"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(inPfactory.GetProtocol(transport), outPfactory.GetProtocol(transport))
-	})
-}
-
-// NewThriftHandlerFunc2 is same as NewThriftHandlerFunc but requires a Context as its first param.
-func NewThriftHandlerFunc2(ctx context.Context, processor TProcessor2,
-	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(ctx, 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) {
diff --git a/lib/go/thrift/http_transport_go17.go b/lib/go/thrift/http_transport_go17.go
new file mode 100644
index 0000000..1313ac2
--- /dev/null
+++ b/lib/go/thrift/http_transport_go17.go
@@ -0,0 +1,38 @@
+// +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))
+	})
+}
diff --git a/lib/go/thrift/http_transport_pre_go17.go b/lib/go/thrift/http_transport_pre_go17.go
new file mode 100644
index 0000000..13aa1c1
--- /dev/null
+++ b/lib/go/thrift/http_transport_pre_go17.go
@@ -0,0 +1,40 @@
+// +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))
+	})
+}
diff --git a/lib/go/thrift/multiplexed_processor.go b/lib/go/thrift/multiplexed_processor.go
deleted file mode 100644
index d205db8..0000000
--- a/lib/go/thrift/multiplexed_processor.go
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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"
-)
-
-/*
-TMultiplexedProcessor2 is a TProcessor allowing
-a single TServer to provide multiple services with
-context support in TProcessor.
-
-To do so, you instantiate the processor and then register additional
-processors with it, as shown in the following example:
-
-var processor = thrift.NewTMultiplexedProcessor2()
-
-firstProcessor :=
-processor.RegisterProcessor("FirstService", firstProcessor)
-
-processor.registerProcessor(
-  "Calculator",
-  Calculator.NewCalculatorProcessor(&CalculatorHandler{}),
-)
-
-processor.registerProcessor(
-  "WeatherReport",
-  WeatherReport.NewWeatherReportProcessor(&WeatherReportHandler{}),
-)
-
-serverTransport, err := thrift.NewTServerSocketTimeout(addr, TIMEOUT)
-if err != nil {
-  t.Fatal("Unable to create server socket", err)
-}
-server := thrift.NewTSimpleServer2(processor, serverTransport)
-server.Serve();
-*/
-
-type TMultiplexedProcessor2 struct {
-	serviceProcessorMap map[string]TProcessor2
-	DefaultProcessor    TProcessor2
-}
-
-func NewTMultiplexedProcessor2() *TMultiplexedProcessor2 {
-	return &TMultiplexedProcessor2{
-		serviceProcessorMap: make(map[string]TProcessor2),
-	}
-}
-
-func (t *TMultiplexedProcessor2) RegisterDefault(processor TProcessor2) {
-	t.DefaultProcessor = processor
-}
-
-func (t *TMultiplexedProcessor2) RegisterProcessor(name string, processor TProcessor2) {
-	if t.serviceProcessorMap == nil {
-		t.serviceProcessorMap = make(map[string]TProcessor2)
-	}
-	t.serviceProcessorMap[name] = processor
-}
-
-func (t *TMultiplexedProcessor2) 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)
-}
diff --git a/lib/go/thrift/multiplexed_protocol.go b/lib/go/thrift/multiplexed_protocol.go
index 6ae7be6..b7f4f8a 100644
--- a/lib/go/thrift/multiplexed_protocol.go
+++ b/lib/go/thrift/multiplexed_protocol.go
@@ -19,11 +19,6 @@
 
 package thrift
 
-import (
-	"fmt"
-	"strings"
-)
-
 /*
 TMultiplexedProtocol is a protocol-independent concrete decorator
 that allows a Thrift client to communicate with a multiplexing Thrift server,
@@ -76,11 +71,33 @@
 }
 
 /*
-This is the non-context version for TProcessor.
+TMultiplexedProcessor is a TProcessor allowing
+a single TServer to provide multiple services.
 
-See description at file: multiplexed_processor.go
+To do so, you instantiate the processor and then register additional
+processors with it, as shown in the following example:
 
-Deprecated: use TMultiplexedProcessor2 for strong server programming.
+var processor = thrift.NewTMultiplexedProcessor()
+
+firstProcessor :=
+processor.RegisterProcessor("FirstService", firstProcessor)
+
+processor.registerProcessor(
+  "Calculator",
+  Calculator.NewCalculatorProcessor(&CalculatorHandler{}),
+)
+
+processor.registerProcessor(
+  "WeatherReport",
+  WeatherReport.NewWeatherReportProcessor(&WeatherReportHandler{}),
+)
+
+serverTransport, err := thrift.NewTServerSocketTimeout(addr, TIMEOUT)
+if err != nil {
+  t.Fatal("Unable to create server socket", err)
+}
+server := thrift.NewTSimpleServer2(processor, serverTransport)
+server.Serve();
 */
 
 type TMultiplexedProcessor struct {
@@ -105,31 +122,6 @@
 	t.serviceProcessorMap[name] = processor
 }
 
-func (t *TMultiplexedProcessor) Process(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(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(smb, out)
-}
-
 //Protocol that use stored message for ReadMessageBegin
 type storedMessageProtocol struct {
 	TProtocol
diff --git a/lib/go/thrift/multiplexed_protocol_go17.go b/lib/go/thrift/multiplexed_protocol_go17.go
new file mode 100644
index 0000000..c71035e
--- /dev/null
+++ b/lib/go/thrift/multiplexed_protocol_go17.go
@@ -0,0 +1,53 @@
+// +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)
+}
diff --git a/lib/go/thrift/multiplexed_protocol_pre_go17.go b/lib/go/thrift/multiplexed_protocol_pre_go17.go
new file mode 100644
index 0000000..5c27b38
--- /dev/null
+++ b/lib/go/thrift/multiplexed_protocol_pre_go17.go
@@ -0,0 +1,54 @@
+// +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)
+}
diff --git a/lib/go/thrift/pre_go17.go b/lib/go/thrift/pre_go17.go
new file mode 100644
index 0000000..cb564b8
--- /dev/null
+++ b/lib/go/thrift/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 thrift
+
+import "golang.org/x/net/context"
+
+var defaultCtx = context.Background()
diff --git a/lib/go/thrift/processor.go b/lib/go/thrift/processor.go
index 7f8f365..566aaaf 100644
--- a/lib/go/thrift/processor.go
+++ b/lib/go/thrift/processor.go
@@ -1,3 +1,5 @@
+// +build !go1.7
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
@@ -19,23 +21,14 @@
 
 package thrift
 
-import "context"
+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(in, out TProtocol) (bool, TException)
-}
-
-type TProcessorFunction interface {
-	Process(seqId int32, in, out TProtocol) (bool, TException)
-}
-
-// TProcessor2 is TProcessor with ctx as its first argument.
-type TProcessor2 interface {
 	Process(ctx context.Context, in, out TProtocol) (bool, TException)
 }
 
-type TProcessorFunction2 interface {
+type TProcessorFunction interface {
 	Process(ctx context.Context, seqId int32, in, out TProtocol) (bool, TException)
 }
diff --git a/lib/go/thrift/processor_factory2.go b/lib/go/thrift/processor_factory2.go
deleted file mode 100644
index bd587ad..0000000
--- a/lib/go/thrift/processor_factory2.go
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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
-
-// The default processor2 factory just returns a singleton
-// instance.
-// The TProcessorFactory2 is a context version of the orignal.
-type TProcessorFactory2 interface {
-	GetProcessor(trans TTransport) TProcessor2
-}
-
-type tProcessorFactory2 struct {
-	processor TProcessor2
-}
-
-func NewTProcessorFactory2(p TProcessor2) TProcessorFactory2 {
-	return &tProcessorFactory2{processor: p}
-}
-
-func (p *tProcessorFactory2) GetProcessor(trans TTransport) TProcessor2 {
-	return p.processor
-}
-
-/**
- * The default processor factory2 just returns a singleton
- * instance.
- */
-type TProcessorFunctionFactory2 interface {
-	GetProcessorFunction(trans TTransport) TProcessorFunction2
-}
-
-type tProcessorFunctionFactory2 struct {
-	processor TProcessorFunction2
-}
-
-func NewTProcessorFunctionFactory2(p TProcessorFunction2) TProcessorFunctionFactory2 {
-	return &tProcessorFunctionFactory2{processor: p}
-}
-
-func (p *tProcessorFunctionFactory2) GetProcessorFunction(trans TTransport) TProcessorFunction2 {
-	return p.processor
-}
diff --git a/lib/go/thrift/processor_go17.go b/lib/go/thrift/processor_go17.go
new file mode 100644
index 0000000..fb0b165
--- /dev/null
+++ b/lib/go/thrift/processor_go17.go
@@ -0,0 +1,34 @@
+// +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)
+}
diff --git a/lib/go/thrift/server.go b/lib/go/thrift/server.go
index 3e8a656..f813fa3 100644
--- a/lib/go/thrift/server.go
+++ b/lib/go/thrift/server.go
@@ -33,19 +33,3 @@
 	// all servers are required to be cleanly stoppable.
 	Stop() error
 }
-
-// Same as TServer but use TProcessorFactory2 as processor factory.
-type TServer2 interface {
-	ProcessorFactory() TProcessorFactory2
-	ServerTransport() TServerTransport
-	InputTransportFactory() TTransportFactory
-	OutputTransportFactory() TTransportFactory
-	InputProtocolFactory() TProtocolFactory
-	OutputProtocolFactory() TProtocolFactory
-
-	// Starts the server
-	Serve() error
-	// Stops the server. This is optional on a per-implementation basis. Not
-	// all servers are required to be cleanly stoppable.
-	Stop() error
-}
diff --git a/lib/go/thrift/simple_server.go b/lib/go/thrift/simple_server.go
index 72541b6..37081bd 100644
--- a/lib/go/thrift/simple_server.go
+++ b/lib/go/thrift/simple_server.go
@@ -198,7 +198,7 @@
 			return nil
 		}
 
-		ok, err := processor.Process(inputProtocol, outputProtocol)
+		ok, err := processor.Process(defaultCtx, inputProtocol, outputProtocol)
 		if err, ok := err.(TTransportException); ok && err.TypeId() == END_OF_FILE {
 			return nil
 		} else if err != nil {
diff --git a/lib/go/thrift/simple_server2.go b/lib/go/thrift/simple_server2.go
deleted file mode 100644
index 9e9961f..0000000
--- a/lib/go/thrift/simple_server2.go
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * 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"
-	"log"
-	"runtime/debug"
-	"sync"
-)
-
-/*
- * This is only a simple sample same as TSimpleServer but add context
- * usage support.
- */
-type TSimpleServer2 struct {
-	quit chan struct{}
-
-	processorFactory       TProcessorFactory2
-	serverTransport        TServerTransport
-	inputTransportFactory  TTransportFactory
-	outputTransportFactory TTransportFactory
-	inputProtocolFactory   TProtocolFactory
-	outputProtocolFactory  TProtocolFactory
-	sync.WaitGroup
-}
-
-func NewTSimpleServerWithContext(processor TProcessor2, serverTransport TServerTransport) *TSimpleServer2 {
-	return NewTSimpleServerFactoryWithContext(NewTProcessorFactory2(processor), serverTransport)
-}
-
-func NewTSimpleServerFactoryWithContext(processorFactory TProcessorFactory2, serverTransport TServerTransport) *TSimpleServer2 {
-	return &TSimpleServer2{
-		quit:                   make(chan struct{}, 1),
-		processorFactory:       processorFactory,
-		serverTransport:        serverTransport,
-		inputTransportFactory:  NewTTransportFactory(),
-		outputTransportFactory: NewTTransportFactory(),
-		inputProtocolFactory:   NewTBinaryProtocolFactoryDefault(),
-		outputProtocolFactory:  NewTBinaryProtocolFactoryDefault(),
-	}
-}
-
-func (p *TSimpleServer2) ProcessorFactory() TProcessorFactory2 {
-	return p.processorFactory
-}
-
-func (p *TSimpleServer2) ServerTransport() TServerTransport {
-	return p.serverTransport
-}
-
-func (p *TSimpleServer2) InputTransportFactory() TTransportFactory {
-	return p.inputTransportFactory
-}
-
-func (p *TSimpleServer2) OutputTransportFactory() TTransportFactory {
-	return p.outputTransportFactory
-}
-
-func (p *TSimpleServer2) InputProtocolFactory() TProtocolFactory {
-	return p.inputProtocolFactory
-}
-
-func (p *TSimpleServer2) OutputProtocolFactory() TProtocolFactory {
-	return p.outputProtocolFactory
-}
-
-func (p *TSimpleServer2) Listen() error {
-	return p.serverTransport.Listen()
-}
-
-func (p *TSimpleServer2) AcceptLoop() error {
-	for {
-		client, err := p.serverTransport.Accept()
-		if err != nil {
-			select {
-			case <-p.quit:
-				return nil
-			default:
-			}
-			return err
-		}
-		if client != nil {
-			p.Add(1)
-			go func() {
-				if err := p.processRequests(client); err != nil {
-					log.Println("error processing request:", err)
-				}
-			}()
-		}
-	}
-}
-
-func (p *TSimpleServer2) Serve() error {
-	err := p.Listen()
-	if err != nil {
-		return err
-	}
-	p.AcceptLoop()
-	return nil
-}
-
-var once2 sync.Once
-
-func (p *TSimpleServer2) Stop() error {
-	q := func() {
-		close(p.quit)
-		p.serverTransport.Interrupt()
-		p.Wait()
-	}
-	once2.Do(q)
-	return nil
-}
-
-func (p *TSimpleServer2) processRequests(client TTransport) error {
-	defer p.Done()
-
-	processor := p.processorFactory.GetProcessor(client)
-	inputTransport, err := p.inputTransportFactory.GetTransport(client)
-	if err != nil {
-		return err
-	}
-	outputTransport, err := p.outputTransportFactory.GetTransport(client)
-	if err != nil {
-		return err
-	}
-	inputProtocol := p.inputProtocolFactory.GetProtocol(inputTransport)
-	outputProtocol := p.outputProtocolFactory.GetProtocol(outputTransport)
-	defer func() {
-		if e := recover(); e != nil {
-			log.Printf("panic in processor: %s: %s", e, debug.Stack())
-		}
-	}()
-
-	if inputTransport != nil {
-		defer inputTransport.Close()
-	}
-	if outputTransport != nil {
-		defer outputTransport.Close()
-	}
-	for {
-		select {
-		case <-p.quit:
-			return nil
-		default:
-		}
-
-		ctx := context.Background()
-		ok, err := processor.Process(ctx, inputProtocol, outputProtocol)
-		if err, ok := err.(TTransportException); ok && err.TypeId() == END_OF_FILE {
-			return nil
-		} else if err != nil {
-			return err
-		}
-		if err, ok := err.(TApplicationException); ok && err.TypeId() == UNKNOWN_METHOD {
-			continue
-		}
-		if !ok {
-			break
-		}
-	}
-	return nil
-}
diff --git a/lib/go/thrift/simple_server_test.go b/lib/go/thrift/simple_server_test.go
index 8763a3b..25702e4 100644
--- a/lib/go/thrift/simple_server_test.go
+++ b/lib/go/thrift/simple_server_test.go
@@ -24,14 +24,6 @@
 	"time"
 )
 
-type mockProcessor struct {
-	ProcessFunc func(in, out TProtocol) (bool, TException)
-}
-
-func (m *mockProcessor) Process(in, out TProtocol) (bool, TException) {
-	return m.ProcessFunc(in, out)
-}
-
 type mockServerTransport struct {
 	ListenFunc    func() error
 	AcceptFunc    func() (TTransport, error)