THRIFT-4285 Move TX/RX methods from gen. code to library

This change removes a lot of duplication from generated code and allows
the caller to customize how they can read from / write to the
transport.  Backwards compatible adapters make the change compatible
with existing code in use by consuming applications.

Client: Go

This closes #1382
diff --git a/test/go/Makefile.am b/test/go/Makefile.am
index db27258..6bc97f5 100644
--- a/test/go/Makefile.am
+++ b/test/go/Makefile.am
@@ -30,6 +30,8 @@
 ThriftTest.thrift: $(THRIFTTEST)
 	grep -v list.*map.*list.*map $(THRIFTTEST) > ThriftTest.thrift
 
+.PHONY: gopath
+
 # Thrift for GO has problems with complex map keys: THRIFT-2063
 gopath: $(THRIFT) ThriftTest.thrift
 	mkdir -p src/gen
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index b34c539..ab24cbf 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -38,7 +38,7 @@
 
 func main() {
 	flag.Parse()
-	client, err := common.StartClient(*host, *port, *domain_socket, *transport, *protocol, *ssl)
+	client, _, err := common.StartClient(*host, *port, *domain_socket, *transport, *protocol, *ssl)
 	if err != nil {
 		t.Fatalf("Unable to start client: ", err)
 	}
@@ -128,7 +128,7 @@
 	}
 	bin, err := client.TestBinary(defaultCtx, binout)
 	for i := 0; i < 256; i++ {
-		if (binout[i] != bin[i]) {
+		if binout[i] != bin[i] {
 			t.Fatalf("Unexpected TestBinary() result expected %d, got %d ", binout[i], bin[i])
 		}
 	}
@@ -224,21 +224,21 @@
 	}
 
 	crazy := thrifttest.NewInsanity()
-	crazy.UserMap = map[thrifttest.Numberz]thrifttest.UserId {
-		thrifttest.Numberz_FIVE: 5,
+	crazy.UserMap = map[thrifttest.Numberz]thrifttest.UserId{
+		thrifttest.Numberz_FIVE:  5,
 		thrifttest.Numberz_EIGHT: 8,
 	}
 	truck1 := thrifttest.NewXtruct()
 	truck1.StringThing = "Goodbye4"
-	truck1.ByteThing = 4;
-	truck1.I32Thing = 4;
-	truck1.I64Thing = 4;
+	truck1.ByteThing = 4
+	truck1.I32Thing = 4
+	truck1.I64Thing = 4
 	truck2 := thrifttest.NewXtruct()
 	truck2.StringThing = "Hello2"
-	truck2.ByteThing = 2;
-	truck2.I32Thing = 2;
-	truck2.I64Thing = 2;
-	crazy.Xtructs = []*thrifttest.Xtruct {
+	truck2.ByteThing = 2
+	truck2.I32Thing = 2
+	truck2.I64Thing = 2
+	crazy.Xtructs = []*thrifttest.Xtruct{
 		truck1,
 		truck2,
 	}
@@ -248,17 +248,17 @@
 	}
 	if !reflect.DeepEqual(crazy, insanity[1][2]) {
 		t.Fatalf("Unexpected TestInsanity() first result expected %#v, got %#v ",
-		crazy,
-		insanity[1][2])
+			crazy,
+			insanity[1][2])
 	}
 	if !reflect.DeepEqual(crazy, insanity[1][3]) {
 		t.Fatalf("Unexpected TestInsanity() second result expected %#v, got %#v ",
-		crazy,
-		insanity[1][3])
+			crazy,
+			insanity[1][3])
 	}
 	if len(insanity[2][6].UserMap) > 0 || len(insanity[2][6].Xtructs) > 0 {
 		t.Fatalf("Unexpected TestInsanity() non-empty result got %#v ",
-		insanity[2][6])
+			insanity[2][6])
 	}
 
 	xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index 4251d91..236ce43 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -41,7 +41,7 @@
 	domain_socket string,
 	transport string,
 	protocol string,
-	ssl bool) (client *thrifttest.ThriftTestClient, err error) {
+	ssl bool) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
 
 	hostPort := fmt.Sprintf("%s:%d", host, port)
 
@@ -56,12 +56,11 @@
 	case "binary":
 		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
 	default:
-		return nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+		return nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
 	}
 	if debugClientProtocol {
 		protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "client:")
 	}
-	var trans thrift.TTransport
 	if ssl {
 		trans, err = thrift.NewTSSLSocket(hostPort, &tls.Config{InsecureSkipVerify: true})
 	} else {
@@ -72,7 +71,7 @@
 		}
 	}
 	if err != nil {
-		return nil, err
+		return nil, nil, err
 	}
 	switch transport {
 	case "http":
@@ -86,29 +85,25 @@
 		} else {
 			trans, err = thrift.NewTHttpPostClient(fmt.Sprintf("http://%s/", hostPort))
 		}
-
-		if err != nil {
-			return nil, err
-		}
-
 	case "framed":
 		trans = thrift.NewTFramedTransport(trans)
 	case "buffered":
 		trans = thrift.NewTBufferedTransport(trans, 8192)
 	case "zlib":
 		trans, err = thrift.NewTZlibTransport(trans, zlib.BestCompression)
-		if err != nil {
-			return nil, err
-		}
 	case "":
 		trans = trans
 	default:
-		return nil, fmt.Errorf("Invalid transport specified %s", transport)
+		return nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
 	}
-
+	if err != nil {
+		return nil, nil, err
+	}
 	if err = trans.Open(); err != nil {
-		return nil, err
+		return nil, nil, err
 	}
-	client = thrifttest.NewThriftTestClientFactory(trans, protocolFactory)
+	iprot := protocolFactory.GetProtocol(trans)
+	oprot := protocolFactory.GetProtocol(trans)
+	client = thrifttest.NewThriftTestClient(thrift.NewTStandardClient(iprot, oprot))
 	return
 }
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index ecd021f..c4cfd44 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -23,6 +23,7 @@
 	"errors"
 	"gen/thrifttest"
 	"reflect"
+	"sync"
 	"testing"
 	"thrift"
 
@@ -47,10 +48,15 @@
 
 func TestAllConnection(t *testing.T) {
 	certPath = "../../../keys"
+	wg := &sync.WaitGroup{}
+	wg.Add(len(units))
 	for _, unit := range units {
-		t.Logf("%#v", unit)
-		doUnit(t, &unit)
+		go func(u test_unit) {
+			defer wg.Done()
+			doUnit(t, &u)
+		}(unit)
 	}
+	wg.Wait()
 }
 
 func doUnit(t *testing.T, unit *test_unit) {
@@ -62,17 +68,17 @@
 
 	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
 	if err = server.Listen(); err != nil {
-		t.Errorf("Unable to start server", err)
-		t.FailNow()
+		t.Errorf("Unable to start server: %v", err)
+		return
 	}
 	go server.AcceptLoop()
 	defer server.Stop()
-	client, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl)
+	client, trans, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl)
 	if err != nil {
-		t.Errorf("Unable to start client", err)
-		t.FailNow()
+		t.Errorf("Unable to start client: %v", err)
+		return
 	}
-	defer client.Transport.Close()
+	defer trans.Close()
 	callEverythingWithMock(t, client, handler)
 }
 
@@ -273,7 +279,7 @@
 
 	xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
 	if err != nil {
-		t.Errorf("Unexpected error in TestMulti() call: ", err)
+		t.Errorf("Unexpected error in TestMulti() call: %v", err)
 	}
 	if !reflect.DeepEqual(xxs, xxsret) {
 		t.Errorf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
@@ -289,9 +295,12 @@
 
 	// TODO: connection is being closed on this
 	err = client.TestException(defaultCtx, "TException")
-	tex, ok := err.(thrift.TApplicationException)
-	if err == nil || !ok || tex.TypeId() != thrift.INTERNAL_ERROR {
-		t.Errorf("Unexpected TestException() result expected ApplicationError, got %#v ", err)
+	if err == nil {
+		t.Error("expected exception got nil")
+	} else if tex, ok := err.(thrift.TApplicationException); !ok {
+		t.Errorf("Unexpected TestException() result expected ApplicationError, got %T ", err)
+	} else if tex.TypeId() != thrift.INTERNAL_ERROR {
+		t.Errorf("expected internal_error got %v", tex.TypeId())
 	}
 
 	ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme")