THRIFT-5358: Add go.mod file to root directory

Client: go

This unblocks the development under go 1.16+, which starts to complain
when there's no go.mod file in any of the directories.

The current approach is certainly not the best solution ever, for
example it does not run the tests under lib/go/test/tests but copy them
into lib/go/test/gopath/src/sometest and run them there instead, but
those improvements can be done in the future in follow up PRs and this
should be a good enough first step to unblock developments.
diff --git a/test/go/Makefile.am b/test/go/Makefile.am
index eae153c..d7db957 100644
--- a/test/go/Makefile.am
+++ b/test/go/Makefile.am
@@ -19,7 +19,7 @@
 
 BUILT_SOURCES = gopath
 
-THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
+THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift,package_prefix=github.com/apache/thrift/test/go/src/gen/$(COMPILER_EXTRAFLAG)
 THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
 
 precross: bin/testclient bin/testserver
@@ -34,20 +34,16 @@
 	mkdir -p src/gen
 	$(THRIFTCMD) ThriftTest.thrift
 	$(THRIFTCMD) ../StressTest.thrift
-	GOPATH=`pwd` $(GO) get github.com/golang/mock/gomock || true
-	sed -i 's/\"context\"/\"golang.org\/x\/net\/context\"/g' src/github.com/golang/mock/gomock/controller.go || true
-	GOPATH=`pwd` $(GO) get github.com/golang/mock/gomock
-	ln -nfs ../../../lib/go/thrift src/thrift
 	touch gopath
 
 bin/testclient: gopath
-	GOPATH=`pwd` $(GO) install bin/testclient
+	GOPATH=`pwd` $(GO) install -mod=mod ./src/bin/testclient
 
 bin/testserver: gopath
-	GOPATH=`pwd` $(GO) install bin/testserver
+	GOPATH=`pwd` $(GO) install -mod=mod ./src/bin/testserver
 
 bin/stress: gopath
-	GOPATH=`pwd` $(GO) install bin/stress
+	GOPATH=`pwd` $(GO) install -mod=mod ./src/bin/stress
 
 clean-local:
 	$(RM) -r src/gen src/github.com/golang src/thrift bin pkg gopath ThriftTest.thrift
@@ -55,7 +51,7 @@
 check_PROGRAMS: bin/testclient bin/testserver bin/stress
 
 check: gopath genmock
-	GOPATH=`pwd` $(GO) test -v common/...
+	$(GO) test -mod=mod -v ./src/common/...
 
 genmock: gopath
 	sh genmock.sh
diff --git a/test/go/genmock.sh b/test/go/genmock.sh
index 3ba41b9..bccfdf3 100644
--- a/test/go/genmock.sh
+++ b/test/go/genmock.sh
@@ -1,15 +1,12 @@
 #!/bin/sh
+
 set -e
 
-export GOPATH=`pwd`
-export GOBIN=`pwd`/bin
-export GO111MODULE=off
+export GOPATH=$(mktemp -d -t gopath-XXXXXXXXXX)
 
-mkdir -p src/github.com/golang/mock
-cd src/github.com/golang
-curl -fsSL https://github.com/golang/mock/archive/v1.2.0.tar.gz -o mock.tar.gz
-tar -xzvf mock.tar.gz -C mock --strip-components=1
-cd mock/mockgen
-go install .
-cd ../../../../../
-bin/mockgen -destination=src/common/mock_handler.go -package=common gen/thrifttest ThriftTest
+# TODO: Once we dropped support to go 1.15, add "@v1.5.0" suffix to go install
+GO111MODULE=on go install -mod=mod github.com/golang/mock/mockgen
+
+`go env GOPATH`/bin/mockgen -build_flags "-mod=mod" -destination=src/common/mock_handler.go -package=common github.com/apache/thrift/test/go/src/gen/thrifttest ThriftTest
+
+rm -Rf $GOPATH
diff --git a/test/go/src/bin/stress/main.go b/test/go/src/bin/stress/main.go
index f2e0f20..3ff0a39 100644
--- a/test/go/src/bin/stress/main.go
+++ b/test/go/src/bin/stress/main.go
@@ -23,7 +23,6 @@
 	"context"
 	"flag"
 	"fmt"
-	"gen/stress"
 	"log"
 	_ "net/http/pprof"
 	"os"
@@ -31,8 +30,10 @@
 	"runtime/pprof"
 	"sync"
 	"sync/atomic"
-	"thrift"
 	"time"
+
+	"github.com/apache/thrift/lib/go/thrift"
+	"github.com/apache/thrift/test/go/src/gen/stress"
 )
 
 var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file")
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 4357ee8..39ee95b 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -20,13 +20,14 @@
 package main
 
 import (
-	"common"
 	"context"
 	"flag"
-	"gen/thrifttest"
 	t "log"
 	"reflect"
-	"thrift"
+
+	"github.com/apache/thrift/lib/go/thrift"
+	"github.com/apache/thrift/test/go/src/common"
+	"github.com/apache/thrift/test/go/src/gen/thrifttest"
 )
 
 var host = flag.String("host", "localhost", "Host to connect")
@@ -50,8 +51,8 @@
 }
 
 var rmapmap = map[int32]map[int32]int32{
-	-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
-	4:  map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
+	-4: {-4: -4, -3: -3, -2: -2, -1: -1},
+	4:  {4: 4, 3: 3, 2: 2, 1: 1},
 }
 
 var xxs = &thrifttest.Xtruct{
diff --git a/test/go/src/bin/testserver/main.go b/test/go/src/bin/testserver/main.go
index 6fc1185..d4bd8b4 100644
--- a/test/go/src/bin/testserver/main.go
+++ b/test/go/src/bin/testserver/main.go
@@ -20,12 +20,13 @@
 package main
 
 import (
-	"common"
 	"flag"
 	"fmt"
 	"log"
 	"net/http"
-	"thrift"
+
+	"github.com/apache/thrift/lib/go/thrift"
+	"github.com/apache/thrift/test/go/src/common"
 )
 
 var host = flag.String("host", "localhost", "Host to connect")
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index ed820ae..15973d8 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -24,9 +24,10 @@
 	"crypto/tls"
 	"flag"
 	"fmt"
-	"gen/thrifttest"
 	"net/http"
-	"thrift"
+
+	"github.com/apache/thrift/lib/go/thrift"
+	"github.com/apache/thrift/test/go/src/gen/thrifttest"
 )
 
 var debugClientProtocol bool
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index 9f93c4c..d5e3c43 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -22,13 +22,14 @@
 import (
 	"context"
 	"errors"
-	"gen/thrifttest"
 	"reflect"
 	"sync"
 	"testing"
-	"thrift"
 
 	"github.com/golang/mock/gomock"
+
+	"github.com/apache/thrift/lib/go/thrift"
+	"github.com/apache/thrift/test/go/src/gen/thrifttest"
 )
 
 type test_unit struct {
@@ -84,8 +85,8 @@
 }
 
 var rmapmap = map[int32]map[int32]int32{
-	-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
-	4:  map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
+	-4: {-4: -4, -3: -3, -2: -2, -1: -1},
+	4:  {4: 4, 3: 3, 2: 2, 1: 1},
 }
 
 var xxs = &thrifttest.Xtruct{
diff --git a/test/go/src/common/context_test.go b/test/go/src/common/context_test.go
index e64dbb9..3e21a54 100644
--- a/test/go/src/common/context_test.go
+++ b/test/go/src/common/context_test.go
@@ -28,8 +28,9 @@
 	"os"
 	"syscall"
 	"testing"
-	"thrift"
 	"time"
+
+	"github.com/apache/thrift/lib/go/thrift"
 )
 
 type slowHttpHandler struct{}
diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go
index 2b22d0c..d91dde4 100644
--- a/test/go/src/common/printing_handler.go
+++ b/test/go/src/common/printing_handler.go
@@ -24,8 +24,9 @@
 	"encoding/hex"
 	"errors"
 	"fmt"
-	. "gen/thrifttest"
 	"time"
+
+	. "github.com/apache/thrift/test/go/src/gen/thrifttest"
 )
 
 var PrintingHandler = &printingHandler{}
@@ -192,7 +193,7 @@
 func (p *printingHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
 	fmt.Printf("testSet({")
 	first := true
-	for k, _ := range thing {
+	for k := range thing {
 		if first {
 			first = false
 		} else {
@@ -256,8 +257,8 @@
 	fmt.Printf("testMapMap(%d)\n", hello)
 
 	r = map[int32]map[int32]int32{
-		-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
-		4:  map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
+		-4: {-4: -4, -3: -3, -2: -2, -1: -1},
+		4:  {4: 4, 3: 3, 2: 2, 1: 1},
 	}
 	return
 }
diff --git a/test/go/src/common/server.go b/test/go/src/common/server.go
index c6674ae..6e3a5d3 100644
--- a/test/go/src/common/server.go
+++ b/test/go/src/common/server.go
@@ -24,8 +24,9 @@
 	"crypto/tls"
 	"flag"
 	"fmt"
-	"gen/thrifttest"
-	"thrift"
+
+	"github.com/apache/thrift/lib/go/thrift"
+	"github.com/apache/thrift/test/go/src/gen/thrifttest"
 )
 
 var (
diff --git a/test/go/src/common/simple_handler.go b/test/go/src/common/simple_handler.go
index 0c9463d..971f17e 100644
--- a/test/go/src/common/simple_handler.go
+++ b/test/go/src/common/simple_handler.go
@@ -21,8 +21,9 @@
 
 import (
 	"errors"
-	. "gen/thrifttest"
 	"time"
+
+	. "github.com/apache/thrift/test/go/src/gen/thrifttest"
 )
 
 var SimpleHandler = &simpleHandler{}
@@ -96,8 +97,8 @@
 func (p *simpleHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
 
 	r = map[int32]map[int32]int32{
-		-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
-		4:  map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
+		-4: {-4: -4, -3: -3, -2: -2, -1: -1},
+		4:  {4: 4, 3: 3, 2: 2, 1: 1},
 	}
 	return
 }