From b71f11e251a711604cea8caad7d493ea57fe8a8f Mon Sep 17 00:00:00 2001 From: Yuxuan 'fishy' Wang Date: Mon, 22 Mar 2021 15:01:00 -0700 Subject: 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. --- tutorial/go/Makefile.am | 24 +++++++++--------------- tutorial/go/src/client.go | 2 +- tutorial/go/src/handler.go | 5 +++-- tutorial/go/src/main.go | 3 ++- tutorial/go/src/server.go | 5 +++-- 5 files changed, 18 insertions(+), 21 deletions(-) (limited to 'tutorial') diff --git a/tutorial/go/Makefile.am b/tutorial/go/Makefile.am index bd57d656f..ed108fd32 100644 --- a/tutorial/go/Makefile.am +++ b/tutorial/go/Makefile.am @@ -18,36 +18,30 @@ # gen-go/tutorial/calculator.go gen-go/shared/shared_service.go: $(top_srcdir)/tutorial/tutorial.thrift - $(THRIFT) --gen go$(COMPILER_EXTRAFLAG) -r $< + $(THRIFT) --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift,package_prefix=github.com/apache/thrift/tutorial/go/gen-go/$(COMPILER_EXTRAFLAG) -r $< all-local: gen-go/tutorial/calculator.go -check: src/github.com/apache/thrift/lib/go/thrift thirdparty-dep - $(THRIFT) -r --gen go$(COMPILER_EXTRAFLAG) $(top_srcdir)/tutorial/tutorial.thrift - cp -r gen-go/* src/ - GOPATH=`pwd` $(GO) build -o go-tutorial ./src - GOPATH=`pwd` $(GO) build -o calculator-remote src/tutorial/calculator-remote/calculator-remote.go - -src/github.com/apache/thrift/lib/go/thrift: - mkdir -p src/github.com/apache/thrift/lib/go - ln -sf $(realpath $(top_srcdir)/lib/go/thrift) src/github.com/apache/thrift/lib/go/thrift +check: thirdparty-dep all + $(GO) build -mod=mod -o go-tutorial ./src + $(GO) build -mod=mod -o calculator-remote ./gen-go/tutorial/calculator-remote/calculator-remote.go thirdparty-dep: tutorialserver: all - GOPATH=`pwd` $(GO) run src/*.go -server=true + $(GO) run -mod=mod src/*.go -server=true tutorialclient: all - GOPATH=`pwd` $(GO) run src/*.go + $(GO) run -mod=mod src/*.go tutorialsecureserver: all - GOPATH=`pwd` $(GO) run src/*.go -server=true -secure=true + $(GO) run -mod=mod src/*.go -server=true -secure=true tutorialsecureclient: all - GOPATH=`pwd` $(GO) run src/*.go -secure=true + $(GO) run -mod=mod src/*.go -secure=true clean-local: - $(RM) -r gen-* src/shared src/tutorial src/git.apache.org go-tutorial calculator-remote + $(RM) -r gen-* go-tutorial calculator-remote EXTRA_DIST = \ src/client.go \ diff --git a/tutorial/go/src/client.go b/tutorial/go/src/client.go index 319ca3e6e..8776f9c0e 100644 --- a/tutorial/go/src/client.go +++ b/tutorial/go/src/client.go @@ -23,9 +23,9 @@ import ( "context" "crypto/tls" "fmt" - "tutorial" "github.com/apache/thrift/lib/go/thrift" + "github.com/apache/thrift/tutorial/go/gen-go/tutorial" ) var defaultCtx = context.Background() diff --git a/tutorial/go/src/handler.go b/tutorial/go/src/handler.go index 5c0eed006..7645fc2a5 100644 --- a/tutorial/go/src/handler.go +++ b/tutorial/go/src/handler.go @@ -22,9 +22,10 @@ package main import ( "context" "fmt" - "shared" "strconv" - "tutorial" + + "github.com/apache/thrift/tutorial/go/gen-go/shared" + "github.com/apache/thrift/tutorial/go/gen-go/tutorial" ) type CalculatorHandler struct { diff --git a/tutorial/go/src/main.go b/tutorial/go/src/main.go index 7730d7b32..afac6bba7 100644 --- a/tutorial/go/src/main.go +++ b/tutorial/go/src/main.go @@ -22,8 +22,9 @@ package main import ( "flag" "fmt" - "github.com/apache/thrift/lib/go/thrift" "os" + + "github.com/apache/thrift/lib/go/thrift" ) func Usage() { diff --git a/tutorial/go/src/server.go b/tutorial/go/src/server.go index 95708eb87..1171ca6d9 100644 --- a/tutorial/go/src/server.go +++ b/tutorial/go/src/server.go @@ -22,8 +22,9 @@ package main import ( "crypto/tls" "fmt" + "github.com/apache/thrift/lib/go/thrift" - "tutorial" + "github.com/apache/thrift/tutorial/go/gen-go/tutorial" ) func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error { @@ -40,7 +41,7 @@ func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift } else { transport, err = thrift.NewTServerSocket(addr) } - + if err != nil { return err } -- cgit v1.2.1