go: Fix things staticcheck complains about
Client: go
Staticcheck is the recommended replacement of the frozen and deprecated
official golint linter [1].
Fix the things it complained about (or add lint:ignore directive) in:
- lib/go/thrift
- lib/go/test/tests
- tutorial/go/src
- test/go/src
- compiler generated code
The majority of the fixes are in the following categories:
- Use of deprecated function (mainly the TConfiguration related ones)
- Redundant break in switch cases
- Unused and unexported variables/fields/functions
Also in the same spirit as fb539ae, remove the error return from
NewTSSLSocket as it can never be non-nil.
This change will be cherry-picked into 0.15.0 branch after merged.
[1]: https://groups.google.com/g/golang-nuts/c/rCP70Aq_tBc
diff --git a/CHANGES.md b/CHANGES.md
index 3932627..5254682 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -8,7 +8,7 @@
- [THRIFT-5347](https://issues.apache.org/jira/browse/THRIFT-5347) - Haskell support dropped
- [THRIFT-5381](https://issues.apache.org/jira/browse/THRIFT-5381) - possible collisions at VOID type with some 3rd-party libraries on Haxe cpp targets
- [THRIFT-5396](https://issues.apache.org/jira/browse/THRIFT-5396) - deprecate netstd "Async" method postfix
-- [THRIFT-5453](https://issues.apache.org/jira/browse/THRIFT-5453) - go: NewTSocketConf no longer returns an error
+- [THRIFT-5453](https://issues.apache.org/jira/browse/THRIFT-5453) - go: NewTSocketConf and NewTSSLSocketConf no longer return an error
### Go
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index 5c052a1..afed5ac 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -1854,7 +1854,7 @@
std::string tstruct_name(publicize(tstruct->get_name()));
out << indent() << "if c := p.CountSetFields" << tstruct_name << "(); c != 1 {" << endl
<< indent()
- << " return fmt.Errorf(\"%T write union: exactly one field must be set (%d set).\", p, c)"
+ << " return fmt.Errorf(\"%T write union: exactly one field must be set (%d set)\", p, c)"
<< endl << indent() << "}" << endl;
}
out << indent() << "if err := oprot.WriteStructBegin(ctx, \"" << name << "\"); err != nil {" << endl;
@@ -2489,6 +2489,7 @@
f_remote << indent() << endl;
f_remote << indent() << "cmd := flag.Arg(0)" << endl;
f_remote << indent() << "var err error" << endl;
+ f_remote << indent() << "var cfg *thrift.TConfiguration = nil" << endl;
f_remote << indent() << "if useHttp {" << endl;
f_remote << indent() << " trans, err = thrift.NewTHttpClient(parsedUrl.String())" << endl;
f_remote << indent() << " if len(headers) > 0 {" << endl;
@@ -2507,14 +2508,13 @@
f_remote << indent() << " os.Exit(1)" << endl;
f_remote << indent() << " }" << endl;
f_remote << indent() << " }" << endl;
- f_remote << indent() << " trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))"
- << endl;
+ f_remote << indent() << " trans = thrift.NewTSocketConf(net.JoinHostPort(host, portStr), cfg)" << endl;
f_remote << indent() << " if err != nil {" << endl;
f_remote << indent() << " fmt.Fprintln(os.Stderr, \"error resolving address:\", err)" << endl;
f_remote << indent() << " os.Exit(1)" << endl;
f_remote << indent() << " }" << endl;
f_remote << indent() << " if framed {" << endl;
- f_remote << indent() << " trans = thrift.NewTFramedTransport(trans)" << endl;
+ f_remote << indent() << " trans = thrift.NewTFramedTransportConf(trans, cfg)" << endl;
f_remote << indent() << " }" << endl;
f_remote << indent() << "}" << endl;
f_remote << indent() << "if err != nil {" << endl;
@@ -2525,16 +2525,16 @@
f_remote << indent() << "var protocolFactory thrift.TProtocolFactory" << endl;
f_remote << indent() << "switch protocol {" << endl;
f_remote << indent() << "case \"compact\":" << endl;
- f_remote << indent() << " protocolFactory = thrift.NewTCompactProtocolFactory()" << endl;
+ f_remote << indent() << " protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg)" << endl;
f_remote << indent() << " break" << endl;
f_remote << indent() << "case \"simplejson\":" << endl;
- f_remote << indent() << " protocolFactory = thrift.NewTSimpleJSONProtocolFactory()" << endl;
+ f_remote << indent() << " protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg)" << endl;
f_remote << indent() << " break" << endl;
f_remote << indent() << "case \"json\":" << endl;
f_remote << indent() << " protocolFactory = thrift.NewTJSONProtocolFactory()" << endl;
f_remote << indent() << " break" << endl;
f_remote << indent() << "case \"binary\", \"\":" << endl;
- f_remote << indent() << " protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()" << endl;
+ f_remote << indent() << " protocolFactory = thrift.NewTBinaryProtocolFactoryConf(cfg)" << endl;
f_remote << indent() << " break" << endl;
f_remote << indent() << "default:" << endl;
f_remote << indent() << " fmt.Fprintln(os.Stderr, \"Invalid protocol specified: \", protocol)"
diff --git a/go.sum b/go.sum
index 646b11a..cfde584 100644
--- a/go.sum
+++ b/go.sum
@@ -2,6 +2,7 @@
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -9,6 +10,8 @@
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e h1:aZzprAO9/8oim3qStq3wc1Xuxx4QmAGriC4VU4ojemQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/lib/go/test/tests/client_error_test.go b/lib/go/test/tests/client_error_test.go
index 64339dc..385f6f5 100644
--- a/lib/go/test/tests/client_error_test.go
+++ b/lib/go/test/tests/client_error_test.go
@@ -406,7 +406,9 @@
if failAt == 50 {
err = failWith
}
+ //lint:ignore SA4006 to keep it consistent with other checks above
last = protocol.EXPECT().ReadMessageEnd(context.Background()).Return(err).After(last)
+ //lint:ignore S1008 to keep it consistent with other checks above
if failAt == 50 {
return true
}
@@ -631,7 +633,9 @@
if failAt == 10 {
err = failWith
}
+ //lint:ignore SA4006 to keep it consistent with other checks above
last = protocol.EXPECT().ReadMessageEnd(context.Background()).Return(err).After(last)
+ //lint:ignore S1008 to keep it consistent with other checks above
if failAt == 10 {
return true
}
diff --git a/lib/go/test/tests/multiplexed_protocol_test.go b/lib/go/test/tests/multiplexed_protocol_test.go
index a5975b7..72f174e 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -51,8 +51,12 @@
}
func createTransport(addr net.Addr) (thrift.TTransport, error) {
- socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT, TIMEOUT)
- transport := thrift.NewTFramedTransport(socket)
+ cfg := &thrift.TConfiguration{
+ ConnectTimeout: TIMEOUT,
+ SocketTimeout: TIMEOUT,
+ }
+ socket := thrift.NewTSocketFromAddrConf(addr, cfg)
+ transport := thrift.NewTFramedTransportConf(socket, cfg)
err := transport.Open()
if err != nil {
return nil, err
@@ -62,9 +66,9 @@
func TestMultiplexedProtocolFirst(t *testing.T) {
processor := thrift.NewTMultiplexedProcessor()
- protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory := thrift.NewTBinaryProtocolFactoryConf(nil)
transportFactory := thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
addr := FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
@@ -87,7 +91,7 @@
t.Fatal(err)
}
defer transport.Close()
- protocol := thrift.NewTMultiplexedProtocol(thrift.NewTBinaryProtocolTransport(transport), "FirstService")
+ protocol := thrift.NewTMultiplexedProtocol(thrift.NewTBinaryProtocolConf(transport, nil), "FirstService")
client := multiplexedprotocoltest.NewFirstClient(thrift.NewTStandardClient(protocol, protocol))
@@ -101,9 +105,9 @@
func TestMultiplexedProtocolSecond(t *testing.T) {
processor := thrift.NewTMultiplexedProcessor()
- protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory := thrift.NewTBinaryProtocolFactoryConf(nil)
transportFactory := thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
addr := FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
@@ -126,7 +130,7 @@
t.Fatal(err)
}
defer transport.Close()
- protocol := thrift.NewTMultiplexedProtocol(thrift.NewTBinaryProtocolTransport(transport), "SecondService")
+ protocol := thrift.NewTMultiplexedProtocol(thrift.NewTBinaryProtocolConf(transport, nil), "SecondService")
client := multiplexedprotocoltest.NewSecondClient(thrift.NewTStandardClient(protocol, protocol))
@@ -140,9 +144,9 @@
func TestMultiplexedProtocolLegacy(t *testing.T) {
processor := thrift.NewTMultiplexedProcessor()
- protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory := thrift.NewTBinaryProtocolFactoryConf(nil)
transportFactory := thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
addr := FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
@@ -167,10 +171,10 @@
}
defer transport.Close()
- protocol := thrift.NewTBinaryProtocolTransport(transport)
+ protocol := thrift.NewTBinaryProtocolConf(transport, nil)
client := multiplexedprotocoltest.NewSecondClient(thrift.NewTStandardClient(protocol, protocol))
- ret, err := client.ReturnTwo(defaultCtx)
+ _, err = client.ReturnTwo(defaultCtx)
//expect error since default processor is not registered
if err == nil {
t.Fatal("Expecting error")
@@ -185,10 +189,10 @@
}
defer transport.Close()
- protocol = thrift.NewTBinaryProtocolTransport(transport)
+ protocol = thrift.NewTBinaryProtocolConf(transport, nil)
client = multiplexedprotocoltest.NewSecondClient(thrift.NewTStandardClient(protocol, protocol))
- ret, err = client.ReturnTwo(defaultCtx)
+ ret, err := client.ReturnTwo(defaultCtx)
if err != nil {
t.Fatal("Unable to call legacy server:", err)
}
diff --git a/lib/go/test/tests/one_way_test.go b/lib/go/test/tests/one_way_test.go
index 295dc1f..6661812 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -66,8 +66,12 @@
}
func TestInitOnewayClient(t *testing.T) {
- transport := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT, TIMEOUT)
- protocol := thrift.NewTBinaryProtocolTransport(transport)
+ cfg := &thrift.TConfiguration{
+ ConnectTimeout: TIMEOUT,
+ SocketTimeout: TIMEOUT,
+ }
+ transport := thrift.NewTSocketFromAddrConf(addr, cfg)
+ protocol := thrift.NewTBinaryProtocolConf(transport, cfg)
client = onewaytest.NewOneWayClient(thrift.NewTStandardClient(protocol, protocol))
err := transport.Open()
if err != nil {
diff --git a/lib/go/test/tests/protocols_test.go b/lib/go/test/tests/protocols_test.go
index 351fe59..d4b53f2 100644
--- a/lib/go/test/tests/protocols_test.go
+++ b/lib/go/test/tests/protocols_test.go
@@ -26,8 +26,11 @@
"github.com/apache/thrift/lib/go/thrift"
)
-func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
- transportFactory thrift.TTransportFactory) {
+func RunSocketTestSuite(
+ t *testing.T,
+ protocolFactory thrift.TProtocolFactory,
+ transportFactory thrift.TTransportFactory,
+) {
// server
var err error
addr = FindAvailableTCPServerPort()
@@ -42,7 +45,12 @@
go server.Serve()
// client
- var transport thrift.TTransport = thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT, TIMEOUT)
+ cfg := &thrift.TConfiguration{
+ ConnectTimeout: TIMEOUT,
+ SocketTimeout: TIMEOUT,
+ }
+ thrift.PropagateTConfiguration(transportFactory, cfg)
+ var transport thrift.TTransport = thrift.NewTSocketFromAddrConf(addr, cfg)
transport, err = transportFactory.GetTransport(transport)
if err != nil {
t.Fatal(err)
@@ -60,39 +68,57 @@
// Run test suite using TJSONProtocol
func TestTJSONProtocol(t *testing.T) {
- RunSocketTestSuite(t,
+ RunSocketTestSuite(
+ t,
thrift.NewTJSONProtocolFactory(),
- thrift.NewTTransportFactory())
- RunSocketTestSuite(t,
+ thrift.NewTTransportFactory(),
+ )
+ RunSocketTestSuite(
+ t,
thrift.NewTJSONProtocolFactory(),
- thrift.NewTBufferedTransportFactory(8912))
- RunSocketTestSuite(t,
+ thrift.NewTBufferedTransportFactory(8912),
+ )
+ RunSocketTestSuite(
+ t,
thrift.NewTJSONProtocolFactory(),
- thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
+ thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil),
+ )
}
// Run test suite using TBinaryProtocol
func TestTBinaryProtocol(t *testing.T) {
- RunSocketTestSuite(t,
- thrift.NewTBinaryProtocolFactoryDefault(),
- thrift.NewTTransportFactory())
- RunSocketTestSuite(t,
- thrift.NewTBinaryProtocolFactoryDefault(),
- thrift.NewTBufferedTransportFactory(8912))
- RunSocketTestSuite(t,
- thrift.NewTBinaryProtocolFactoryDefault(),
- thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
+ RunSocketTestSuite(
+ t,
+ thrift.NewTBinaryProtocolFactoryConf(nil),
+ thrift.NewTTransportFactory(),
+ )
+ RunSocketTestSuite(
+ t,
+ thrift.NewTBinaryProtocolFactoryConf(nil),
+ thrift.NewTBufferedTransportFactory(8912),
+ )
+ RunSocketTestSuite(
+ t,
+ thrift.NewTBinaryProtocolFactoryConf(nil),
+ thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil),
+ )
}
// Run test suite using TCompactBinaryProtocol
func TestTCompactProtocol(t *testing.T) {
- RunSocketTestSuite(t,
- thrift.NewTCompactProtocolFactory(),
- thrift.NewTTransportFactory())
- RunSocketTestSuite(t,
- thrift.NewTCompactProtocolFactory(),
- thrift.NewTBufferedTransportFactory(8912))
- RunSocketTestSuite(t,
- thrift.NewTCompactProtocolFactory(),
- thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
+ RunSocketTestSuite(
+ t,
+ thrift.NewTCompactProtocolFactoryConf(nil),
+ thrift.NewTTransportFactory(),
+ )
+ RunSocketTestSuite(
+ t,
+ thrift.NewTCompactProtocolFactoryConf(nil),
+ thrift.NewTBufferedTransportFactory(8912),
+ )
+ RunSocketTestSuite(
+ t,
+ thrift.NewTCompactProtocolFactoryConf(nil),
+ thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil),
+ )
}
diff --git a/lib/go/test/tests/struct_args_rets_test.go b/lib/go/test/tests/struct_args_rets_test.go
index df6b746..1f3d0b2 100644
--- a/lib/go/test/tests/struct_args_rets_test.go
+++ b/lib/go/test/tests/struct_args_rets_test.go
@@ -23,7 +23,9 @@
st "github.com/apache/thrift/lib/go/test/gopath/src/servicestest"
)
-//this function is never called, it will fail to compile if check is failed
+// This function is never called, it will fail to compile if check is failed
+//
+//lint:ignore U1000 see above ^
func staticCheckStructArgsResults() {
//Check that struct args and results are passed by reference
var sa *st.StructA = &st.StructA{}
diff --git a/lib/go/test/tests/thrifttest_driver.go b/lib/go/test/tests/thrifttest_driver.go
index b351295..29ccd53 100644
--- a/lib/go/test/tests/thrifttest_driver.go
+++ b/lib/go/test/tests/thrifttest_driver.go
@@ -66,7 +66,9 @@
"Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " +
"Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " +
"Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " +
+ //lint:ignore ST1018 intentionally use unicode characters here
"Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " +
+ //lint:ignore ST1018 intentionally use unicode characters here
"Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " +
"Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " +
"Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " +
@@ -222,7 +224,7 @@
}
err := client.TestException(defaultCtx, "Xception")
- if e, ok := err.(*thrifttest.Xception); ok == false || e == nil {
+ if e, ok := err.(*thrifttest.Xception); !ok || e == nil {
t.Fatal("TestException Xception failed:", err)
} else if e.ErrorCode != 1001 || e.Message != "Xception" {
t.Fatal("TestException Xception failed:", e)
diff --git a/lib/go/thrift/application_exception.go b/lib/go/thrift/application_exception.go
index 32d5b01..ed85a64 100644
--- a/lib/go/thrift/application_exception.go
+++ b/lib/go/thrift/application_exception.go
@@ -145,6 +145,9 @@
func (p *tApplicationException) Write(ctx context.Context, oprot TProtocol) (err error) {
err = oprot.WriteStructBegin(ctx, "TApplicationException")
+ if err != nil {
+ return
+ }
if len(p.Error()) > 0 {
err = oprot.WriteFieldBegin(ctx, "message", STRING, 1)
if err != nil {
diff --git a/lib/go/thrift/compact_protocol.go b/lib/go/thrift/compact_protocol.go
index e0de077..ff3999c 100644
--- a/lib/go/thrift/compact_protocol.go
+++ b/lib/go/thrift/compact_protocol.go
@@ -334,7 +334,8 @@
if e != nil {
return NewTProtocolException(e)
}
- if len(value) > 0 {
+ if len(value) == 0 {
+ return nil
}
_, e = p.trans.WriteString(value)
return e
@@ -722,25 +723,12 @@
return (n << 1) ^ (n >> 31)
}
-func (p *TCompactProtocol) fixedUint64ToBytes(n uint64, buf []byte) {
- binary.LittleEndian.PutUint64(buf, n)
-}
-
-func (p *TCompactProtocol) fixedInt64ToBytes(n int64, buf []byte) {
- binary.LittleEndian.PutUint64(buf, uint64(n))
-}
-
// Writes a byte without any possibility of all that field header nonsense.
// Used internally by other writing methods that know they need to write a byte.
func (p *TCompactProtocol) writeByteDirect(b byte) error {
return p.trans.WriteByte(b)
}
-// Writes a byte without any possibility of all that field header nonsense.
-func (p *TCompactProtocol) writeIntAsByteDirect(n int) (int, error) {
- return 1, p.writeByteDirect(byte(n))
-}
-
//
// Internal reading methods
//
@@ -797,13 +785,6 @@
// Note that it's important that the mask bytes are long literals,
// otherwise they'll default to ints, and when you shift an int left 56 bits,
// you just get a messed up int.
-func (p *TCompactProtocol) bytesToInt64(b []byte) int64 {
- return int64(binary.LittleEndian.Uint64(b))
-}
-
-// Note that it's important that the mask bytes are long literals,
-// otherwise they'll default to ints, and when you shift an int left 56 bits,
-// you just get a messed up int.
func (p *TCompactProtocol) bytesToUint64(b []byte) uint64 {
return binary.LittleEndian.Uint64(b)
}
diff --git a/lib/go/thrift/framed_transport.go b/lib/go/thrift/framed_transport.go
index f683e7f..2156dd7 100644
--- a/lib/go/thrift/framed_transport.go
+++ b/lib/go/thrift/framed_transport.go
@@ -200,7 +200,7 @@
return err
}
size := binary.BigEndian.Uint32(buf)
- if size < 0 || size > uint32(p.cfg.GetMaxFrameSize()) {
+ if size > uint32(p.cfg.GetMaxFrameSize()) {
return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, fmt.Sprintf("Incorrect frame size (%d)", size))
}
_, err := io.CopyN(&p.readBuf, p.reader, int64(size))
diff --git a/lib/go/thrift/http_client.go b/lib/go/thrift/http_client.go
index 1501586..ce62c96 100644
--- a/lib/go/thrift/http_client.go
+++ b/lib/go/thrift/http_client.go
@@ -36,13 +36,11 @@
var DefaultHttpClient *http.Client = http.DefaultClient
type THttpClient struct {
- client *http.Client
- response *http.Response
- url *url.URL
- requestBuffer *bytes.Buffer
- header http.Header
- nsecConnectTimeout int64
- nsecReadTimeout int64
+ client *http.Client
+ response *http.Response
+ url *url.URL
+ requestBuffer *bytes.Buffer
+ header http.Header
}
type THttpClientTransportFactory struct {
diff --git a/lib/go/thrift/json_protocol.go b/lib/go/thrift/json_protocol.go
index 98764fa..d248ecf 100644
--- a/lib/go/thrift/json_protocol.go
+++ b/lib/go/thrift/json_protocol.go
@@ -501,44 +501,6 @@
return elemType, size, nil
}
-func (p *TJSONProtocol) readElemListBegin() (elemType TType, size int, e error) {
- if isNull, e := p.ParseListBegin(); isNull || e != nil {
- return VOID, 0, e
- }
- // We don't really use the ctx in ReadString implementation,
- // so this is safe for now.
- // We might want to add context to ParseElemListBegin if we start to use
- // ctx in ReadString implementation in the future.
- sElemType, err := p.ReadString(context.Background())
- if err != nil {
- return VOID, size, err
- }
- elemType, err = p.StringToTypeId(sElemType)
- if err != nil {
- return elemType, size, err
- }
- nSize, _, err2 := p.ParseI64()
- size = int(nSize)
- return elemType, size, err2
-}
-
-func (p *TJSONProtocol) writeElemListBegin(elemType TType, size int) error {
- if e := p.OutputListBegin(); e != nil {
- return e
- }
- s, e1 := p.TypeIdToString(elemType)
- if e1 != nil {
- return e1
- }
- if e := p.OutputString(s); e != nil {
- return e
- }
- if e := p.OutputI64(int64(size)); e != nil {
- return e
- }
- return nil
-}
-
func (p *TJSONProtocol) TypeIdToString(fieldType TType) (string, error) {
switch byte(fieldType) {
case BOOL:
diff --git a/lib/go/thrift/protocol.go b/lib/go/thrift/protocol.go
index 4768c8f..bd76bcc 100644
--- a/lib/go/thrift/protocol.go
+++ b/lib/go/thrift/protocol.go
@@ -174,7 +174,7 @@
}
return self.ReadListEnd(ctx)
default:
- return NewTProtocolExceptionWithType(INVALID_DATA, errors.New(fmt.Sprintf("Unknown data type %d", fieldType)))
+ return NewTProtocolExceptionWithType(INVALID_DATA, fmt.Errorf("Unknown data type %d", fieldType))
}
return nil
}
diff --git a/lib/go/thrift/rich_transport_test.go b/lib/go/thrift/rich_transport_test.go
index 25c3fd5..c516918 100644
--- a/lib/go/thrift/rich_transport_test.go
+++ b/lib/go/thrift/rich_transport_test.go
@@ -62,17 +62,17 @@
}
}
-var someError = errors.New("Some error")
+var errSomeError = errors.New("Some error")
var readByteTests = []struct {
r *mockReader
v byte
err error
}{
- {&mockReader{0, 55, io.EOF}, 0, io.EOF}, // reader sends EOF w/o data
- {&mockReader{0, 55, someError}, 0, someError}, // reader sends some other error
- {&mockReader{1, 55, nil}, 55, nil}, // reader sends data w/o error
- {&mockReader{1, 55, io.EOF}, 55, nil}, // reader sends data with EOF
- {&mockReader{1, 55, someError}, 55, someError}, // reader sends data withsome error
+ {&mockReader{0, 55, io.EOF}, 0, io.EOF}, // reader sends EOF w/o data
+ {&mockReader{0, 55, errSomeError}, 0, errSomeError}, // reader sends some other error
+ {&mockReader{1, 55, nil}, 55, nil}, // reader sends data w/o error
+ {&mockReader{1, 55, io.EOF}, 55, nil}, // reader sends data with EOF
+ {&mockReader{1, 55, errSomeError}, 55, errSomeError}, // reader sends data withsome error
}
type mockReader struct {
diff --git a/lib/go/thrift/serializer_test.go b/lib/go/thrift/serializer_test.go
index 2e37ea2..9d785f9 100644
--- a/lib/go/thrift/serializer_test.go
+++ b/lib/go/thrift/serializer_test.go
@@ -213,20 +213,18 @@
}
func TestSerializer(t *testing.T) {
-
- var protocol_factories map[string]ProtocolFactory
- protocol_factories = make(map[string]ProtocolFactory)
- protocol_factories["Binary"] = NewTBinaryProtocolFactoryDefault()
- protocol_factories["Compact"] = NewTCompactProtocolFactory()
- //protocol_factories["SimpleJSON"] = NewTSimpleJSONProtocolFactory() - write only, can't be read back by design
- protocol_factories["JSON"] = NewTJSONProtocolFactory()
+ protocolFactories := make(map[string]ProtocolFactory)
+ protocolFactories["Binary"] = NewTBinaryProtocolFactoryDefault()
+ protocolFactories["Compact"] = NewTCompactProtocolFactory()
+ //protocolFactories["SimpleJSON"] = NewTSimpleJSONProtocolFactory() - write only, can't be read back by design
+ protocolFactories["JSON"] = NewTJSONProtocolFactory()
tests := make(map[string]func(*testing.T, ProtocolFactory))
tests["Test 1"] = ProtocolTest1
tests["Test 2"] = ProtocolTest2
//tests["Test 3"] = ProtocolTest3 // Example of how to add additional tests
- for name, pf := range protocol_factories {
+ for name, pf := range protocolFactories {
t.Run(
name,
func(t *testing.T) {
@@ -241,7 +239,6 @@
},
)
}
-
}
func TestSerializerPoolAsync(t *testing.T) {
diff --git a/lib/go/thrift/simple_json_protocol.go b/lib/go/thrift/simple_json_protocol.go
index 4967532..c9c450b 100644
--- a/lib/go/thrift/simple_json_protocol.go
+++ b/lib/go/thrift/simple_json_protocol.go
@@ -173,7 +173,6 @@
JSON_INFINITY_BYTES []byte
JSON_NEGATIVE_INFINITY_BYTES []byte
JSON_NAN_BYTES []byte
- json_nonbase_map_elem_bytes []byte
)
func init() {
@@ -194,7 +193,6 @@
JSON_INFINITY_BYTES = []byte{'I', 'n', 'f', 'i', 'n', 'i', 't', 'y'}
JSON_NEGATIVE_INFINITY_BYTES = []byte{'-', 'I', 'n', 'f', 'i', 'n', 'i', 't', 'y'}
JSON_NAN_BYTES = []byte{'N', 'a', 'N'}
- json_nonbase_map_elem_bytes = []byte{']', ',', '['}
}
func jsonQuote(s string) string {
@@ -480,7 +478,6 @@
e := fmt.Errorf("Expected \"true\" but found: %s", string(b))
return value, NewTProtocolExceptionWithType(INVALID_DATA, e)
}
- break
case JSON_FALSE[0]:
b := make([]byte, len(JSON_FALSE))
_, err := p.reader.Read(b)
@@ -493,7 +490,6 @@
e := fmt.Errorf("Expected \"false\" but found: %s", string(b))
return value, NewTProtocolExceptionWithType(INVALID_DATA, e)
}
- break
case JSON_NULL[0]:
b := make([]byte, len(JSON_NULL))
_, err := p.reader.Read(b)
@@ -903,8 +899,6 @@
case ' ', '\r', '\n', '\t':
p.reader.ReadByte()
continue
- default:
- break
}
break
}
@@ -1069,7 +1063,7 @@
e := fmt.Errorf("Expecting end of object \"}\", but found: \"%s\"", line)
return NewTProtocolExceptionWithType(INVALID_DATA, e)
case ' ', '\n', '\r', '\t', '}':
- break
+ // do nothing
}
}
p.parseContextStack.pop()
@@ -1137,7 +1131,7 @@
e := fmt.Errorf("Expecting end of list \"]\", but found: \"%v\"", line)
return NewTProtocolExceptionWithType(INVALID_DATA, e)
case ' ', '\n', '\r', '\t', rune(JSON_RBRACKET[0]):
- break
+ // do nothing
}
}
p.parseContextStack.pop()
@@ -1149,82 +1143,6 @@
return p.ParsePostValue()
}
-func (p *TSimpleJSONProtocol) readSingleValue() (interface{}, TType, error) {
- e := p.readNonSignificantWhitespace()
- if e != nil {
- return nil, VOID, NewTProtocolException(e)
- }
- b, e := p.reader.Peek(1)
- if len(b) > 0 {
- c := b[0]
- switch c {
- case JSON_NULL[0]:
- buf := make([]byte, len(JSON_NULL))
- _, e := p.reader.Read(buf)
- if e != nil {
- return nil, VOID, NewTProtocolException(e)
- }
- if string(JSON_NULL) != string(buf) {
- e = mismatch(string(JSON_NULL), string(buf))
- return nil, VOID, NewTProtocolExceptionWithType(INVALID_DATA, e)
- }
- return nil, VOID, nil
- case JSON_QUOTE:
- p.reader.ReadByte()
- v, e := p.ParseStringBody()
- if e != nil {
- return v, UTF8, NewTProtocolException(e)
- }
- if v == JSON_INFINITY {
- return INFINITY, DOUBLE, nil
- } else if v == JSON_NEGATIVE_INFINITY {
- return NEGATIVE_INFINITY, DOUBLE, nil
- } else if v == JSON_NAN {
- return NAN, DOUBLE, nil
- }
- return v, UTF8, nil
- case JSON_TRUE[0]:
- buf := make([]byte, len(JSON_TRUE))
- _, e := p.reader.Read(buf)
- if e != nil {
- return true, BOOL, NewTProtocolException(e)
- }
- if string(JSON_TRUE) != string(buf) {
- e := mismatch(string(JSON_TRUE), string(buf))
- return true, BOOL, NewTProtocolExceptionWithType(INVALID_DATA, e)
- }
- return true, BOOL, nil
- case JSON_FALSE[0]:
- buf := make([]byte, len(JSON_FALSE))
- _, e := p.reader.Read(buf)
- if e != nil {
- return false, BOOL, NewTProtocolException(e)
- }
- if string(JSON_FALSE) != string(buf) {
- e := mismatch(string(JSON_FALSE), string(buf))
- return false, BOOL, NewTProtocolExceptionWithType(INVALID_DATA, e)
- }
- return false, BOOL, nil
- case JSON_LBRACKET[0]:
- _, e := p.reader.ReadByte()
- return make([]interface{}, 0), LIST, NewTProtocolException(e)
- case JSON_LBRACE[0]:
- _, e := p.reader.ReadByte()
- return make(map[string]interface{}), STRUCT, NewTProtocolException(e)
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'e', 'E', '.', '+', '-', JSON_INFINITY[0], JSON_NAN[0]:
- // assume numeric
- v, e := p.readNumeric()
- return v, DOUBLE, e
- default:
- e := fmt.Errorf("Expected element in list but found '%s' while parsing JSON.", string(c))
- return nil, VOID, NewTProtocolExceptionWithType(INVALID_DATA, e)
- }
- }
- e = fmt.Errorf("Cannot read a single element while parsing JSON.")
- return nil, VOID, NewTProtocolExceptionWithType(INVALID_DATA, e)
-
-}
-
func (p *TSimpleJSONProtocol) readIfNull() (bool, error) {
cont := true
for cont {
@@ -1237,10 +1155,8 @@
return false, nil
case JSON_NULL[0]:
cont = false
- break
case ' ', '\n', '\r', '\t':
p.reader.ReadByte()
- break
}
}
if p.safePeekContains(JSON_NULL) {
@@ -1368,8 +1284,6 @@
case JSON_QUOTE:
if !inQuotes {
inQuotes = true
- } else {
- break
}
default:
e := fmt.Errorf("Unable to parse number starting with character '%c'", c)
diff --git a/lib/go/thrift/ssl_socket.go b/lib/go/thrift/ssl_socket.go
index cd711ff..bee1097 100644
--- a/lib/go/thrift/ssl_socket.go
+++ b/lib/go/thrift/ssl_socket.go
@@ -42,18 +42,22 @@
//
// Example:
//
-// trans, err := thrift.NewTSSLSocketConf("localhost:9090", nil, &TConfiguration{
+// trans := thrift.NewTSSLSocketConf("localhost:9090", &TConfiguration{
// ConnectTimeout: time.Second, // Use 0 for no timeout
// SocketTimeout: time.Second, // Use 0 for no timeout
+//
+// TLSConfig: &tls.Config{
+// // Fill in tls config here.
+// }
// })
-func NewTSSLSocketConf(hostPort string, conf *TConfiguration) (*TSSLSocket, error) {
+func NewTSSLSocketConf(hostPort string, conf *TConfiguration) *TSSLSocket {
if cfg := conf.GetTLSConfig(); cfg != nil && cfg.MinVersion == 0 {
cfg.MinVersion = tls.VersionTLS10
}
return &TSSLSocket{
hostPort: hostPort,
cfg: conf,
- }, nil
+ }
}
// Deprecated: Use NewTSSLSocketConf instead.
@@ -62,7 +66,7 @@
TLSConfig: cfg,
noPropagation: true,
- })
+ }), nil
}
// Deprecated: Use NewTSSLSocketConf instead.
@@ -73,7 +77,7 @@
TLSConfig: cfg,
noPropagation: true,
- })
+ }), nil
}
// NewTSSLSocketFromAddrConf creates a TSSLSocket from a net.Addr.
diff --git a/lib/go/thrift/staticcheck.conf b/lib/go/thrift/staticcheck.conf
new file mode 100644
index 0000000..2ffe850
--- /dev/null
+++ b/lib/go/thrift/staticcheck.conf
@@ -0,0 +1,4 @@
+checks = [
+ "inherit",
+ "-ST1005", # To be consistent with other language libraries we need capitalized error messages.
+]
diff --git a/lib/go/thrift/transport_test.go b/lib/go/thrift/transport_test.go
index 0127803..309cc28 100644
--- a/lib/go/thrift/transport_test.go
+++ b/lib/go/thrift/transport_test.go
@@ -166,12 +166,3 @@
}
return nil, NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "Could not find available server port")
}
-
-func valueInSlice(value string, slice []string) bool {
- for _, v := range slice {
- if value == v {
- return true
- }
- }
- return false
-}
diff --git a/test/go/src/bin/stress/main.go b/test/go/src/bin/stress/main.go
index 9f32676..3273d1b 100644
--- a/test/go/src/bin/stress/main.go
+++ b/test/go/src/bin/stress/main.go
@@ -103,14 +103,14 @@
var transportFactory thrift.TTransportFactory
if *compact {
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(nil)
} else {
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(nil)
}
if *framed {
transportFactory = thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
} else {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
}
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 39ee95b..f0ce052 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -36,7 +36,6 @@
var transport = flag.String("transport", "buffered", "Transport: buffered, framed, http, zlib")
var protocol = flag.String("protocol", "binary", "Protocol: binary, compact, json")
var ssl = flag.Bool("ssl", false, "Encrypted Transport using SSL")
-var zlib = flag.Bool("zlib", false, "Wrapped Transport using Zlib")
var testloops = flag.Int("testloops", 1, "Number of Tests")
func main() {
@@ -131,6 +130,9 @@
binout[i] = byte(i)
}
bin, err := client.TestBinary(defaultCtx, binout)
+ if err != nil {
+ t.Fatalf("TestBinary failed with %v", err)
+ }
for i := 0; i < 256; i++ {
if binout[i] != bin[i] {
t.Fatalf("Unexpected TestBinary() result expected %d, got %d ", binout[i], bin[i])
diff --git a/test/go/src/bin/testserver/main.go b/test/go/src/bin/testserver/main.go
index d4bd8b4..011a71d 100644
--- a/test/go/src/bin/testserver/main.go
+++ b/test/go/src/bin/testserver/main.go
@@ -35,7 +35,6 @@
var transport = flag.String("transport", "buffered", "Transport: buffered, framed, http, zlib")
var protocol = flag.String("protocol", "binary", "Protocol: binary, compact, json, header")
var ssl = flag.Bool("ssl", false, "Encrypted Transport using SSL")
-var zlib = flag.Bool("zlib", false, "Wrapped Transport using Zlib")
var certPath = flag.String("certPath", "keys", "Directory that contains SSL certificates")
func main() {
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index 2015035..f9dfcaf 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -42,32 +42,35 @@
domain_socket string,
transport string,
protocol string,
- ssl bool) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
-
+ ssl bool,
+) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
hostPort := fmt.Sprintf("%s:%d", host, port)
+ cfg := &thrift.TConfiguration{
+ TLSConfig: &tls.Config{
+ InsecureSkipVerify: true,
+ },
+ }
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg)
case "simplejson":
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
+ protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg)
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary":
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(cfg)
case "header":
- protocolFactory = thrift.NewTHeaderProtocolFactory()
+ protocolFactory = thrift.NewTHeaderProtocolFactoryConf(cfg)
default:
- return nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+ return nil, nil, fmt.Errorf("invalid protocol specified %s", protocol)
}
if debugClientProtocol {
protocolFactory = thrift.NewTDebugProtocolFactoryWithLogger(protocolFactory, "client:", thrift.StdLogger(nil))
}
if ssl {
- trans, err = thrift.NewTSSLSocketConf(hostPort, &thrift.TConfiguration{
- TLSConfig: &tls.Config{InsecureSkipVerify: true},
- })
+ trans = thrift.NewTSSLSocketConf(hostPort, cfg)
} else {
if domain_socket != "" {
trans = thrift.NewTSocketConf(domain_socket, nil)
@@ -85,21 +88,21 @@
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
- trans, err = thrift.NewTHttpPostClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
+ trans, err = thrift.NewTHttpClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
fmt.Println(hostPort)
} else {
- trans, err = thrift.NewTHttpPostClient(fmt.Sprintf("http://%s/", hostPort))
+ trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/", hostPort))
}
case "framed":
- trans = thrift.NewTFramedTransport(trans)
+ trans = thrift.NewTFramedTransportConf(trans, cfg)
case "buffered":
trans = thrift.NewTBufferedTransport(trans, 8192)
case "zlib":
trans, err = thrift.NewTZlibTransport(trans, zlib.BestCompression)
case "":
- trans = trans
+ // Do nothing
default:
- return nil, 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
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index d5e3c43..609086b 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -49,7 +49,6 @@
}
func TestAllConnection(t *testing.T) {
- certPath = "../../../keys"
wg := &sync.WaitGroup{}
wg.Add(len(units))
for _, unit := range units {
@@ -67,6 +66,9 @@
handler := NewMockThriftTest(ctrl)
processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+ if err != nil {
+ t.Errorf("GetServerParams failed: %v", err)
+ }
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
if err = server.Listen(); err != nil {
diff --git a/test/go/src/common/context_test.go b/test/go/src/common/context_test.go
index 3e21a54..c6cbad8 100644
--- a/test/go/src/common/context_test.go
+++ b/test/go/src/common/context_test.go
@@ -40,8 +40,6 @@
}
func TestHttpContextTimeout(t *testing.T) {
- certPath = "../../../keys"
-
unit := test_unit{"127.0.0.1", 9096, "", "http", "binary", false}
server := &http.Server{Addr: unit.host + fmt.Sprintf(":%d", unit.port), Handler: slowHttpHandler{}}
@@ -56,6 +54,7 @@
unwrapErr := func(err error) error {
for {
+ //lint:ignore S1034 type switch is more appropriate here.
switch err.(type) {
case thrift.TTransportException:
err = err.(thrift.TTransportException).Err()
diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go
index d91dde4..b726373 100644
--- a/test/go/src/common/printing_handler.go
+++ b/test/go/src/common/printing_handler.go
@@ -26,6 +26,7 @@
"fmt"
"time"
+ //lint:ignore ST1001 allow dot import here
. "github.com/apache/thrift/test/go/src/gen/thrifttest"
)
@@ -333,6 +334,7 @@
e.Message = arg
return e
case "TException":
+ //lint:ignore ST1005 To be consistent with other language libraries.
return errors.New("Just TException")
}
return
diff --git a/test/go/src/common/server.go b/test/go/src/common/server.go
index 6e3a5d3..f48389d 100644
--- a/test/go/src/common/server.go
+++ b/test/go/src/common/server.go
@@ -31,7 +31,6 @@
var (
debugServerProtocol bool
- certPath string
)
func init() {
@@ -46,28 +45,30 @@
protocol string,
ssl bool,
certPath string,
- handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
+ handler thrifttest.ThriftTest,
+) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
var err error
hostPort := fmt.Sprintf("%s:%d", host, port)
+ var cfg *thrift.TConfiguration = nil
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg)
case "simplejson":
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
+ protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg)
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary":
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(nil)
case "header":
- protocolFactory = thrift.NewTHeaderProtocolFactory()
+ protocolFactory = thrift.NewTHeaderProtocolFactoryConf(nil)
default:
- return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+ return nil, nil, nil, nil, fmt.Errorf("invalid protocol specified %s", protocol)
}
if debugServerProtocol {
- protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
+ protocolFactory = thrift.NewTDebugProtocolFactoryWithLogger(protocolFactory, "server:", thrift.StdLogger(nil))
}
var serverTransport thrift.TServerTransport
@@ -98,7 +99,7 @@
transportFactory = nil
case "framed":
transportFactory = thrift.NewTTransportFactory()
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, nil)
case "buffered":
transportFactory = thrift.NewTBufferedTransportFactory(8192)
case "zlib":
@@ -106,7 +107,7 @@
case "":
transportFactory = thrift.NewTTransportFactory()
default:
- return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
+ return nil, nil, nil, nil, fmt.Errorf("invalid transport specified %s", transport)
}
processor := thrifttest.NewThriftTestProcessor(handler)
diff --git a/test/go/src/common/simple_handler.go b/test/go/src/common/simple_handler.go
index 971f17e..fb95457 100644
--- a/test/go/src/common/simple_handler.go
+++ b/test/go/src/common/simple_handler.go
@@ -23,6 +23,7 @@
"errors"
"time"
+ //lint:ignore ST1001 allow dot import here
. "github.com/apache/thrift/test/go/src/gen/thrifttest"
)
@@ -104,6 +105,7 @@
}
func (p *simpleHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
+ //lint:ignore ST1005 To be consistent with other language libraries.
return nil, errors.New("No Insanity")
}
@@ -125,6 +127,7 @@
e.Message = arg
return e
case "TException":
+ //lint:ignore ST1005 To be consistent with other language libraries.
return errors.New("Just TException")
}
return
diff --git a/tutorial/go/src/client.go b/tutorial/go/src/client.go
index 8776f9c..f944cf8 100644
--- a/tutorial/go/src/client.go
+++ b/tutorial/go/src/client.go
@@ -21,7 +21,6 @@
import (
"context"
- "crypto/tls"
"fmt"
"github.com/apache/thrift/lib/go/thrift"
@@ -79,21 +78,14 @@
return err
}
-func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
+func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool, cfg *thrift.TConfiguration) error {
var transport thrift.TTransport
- var err error
if secure {
- cfg := new(tls.Config)
- cfg.InsecureSkipVerify = true
- transport, err = thrift.NewTSSLSocket(addr, cfg)
+ transport = thrift.NewTSSLSocketConf(addr, cfg)
} else {
- transport, err = thrift.NewTSocket(addr)
+ transport = thrift.NewTSocketConf(addr, cfg)
}
- if err != nil {
- fmt.Println("Error opening socket:", err)
- return err
- }
- transport, err = transportFactory.GetTransport(transport)
+ transport, err := transportFactory.GetTransport(transport)
if err != nil {
return err
}
diff --git a/tutorial/go/src/handler.go b/tutorial/go/src/handler.go
index 7645fc2..a9edd26 100644
--- a/tutorial/go/src/handler.go
+++ b/tutorial/go/src/handler.go
@@ -51,13 +51,10 @@
switch w.Op {
case tutorial.Operation_ADD:
val = w.Num1 + w.Num2
- break
case tutorial.Operation_SUBTRACT:
val = w.Num1 - w.Num2
- break
case tutorial.Operation_MULTIPLY:
val = w.Num1 * w.Num2
- break
case tutorial.Operation_DIVIDE:
if w.Num2 == 0 {
ouch := tutorial.NewInvalidOperation()
@@ -67,7 +64,6 @@
return
}
val = w.Num1 / w.Num2
- break
default:
ouch := tutorial.NewInvalidOperation()
ouch.WhatOp = int32(w.Op)
@@ -93,7 +89,7 @@
func (p *CalculatorHandler) GetStruct(ctx context.Context, key int32) (*shared.SharedStruct, error) {
fmt.Print("getStruct(", key, ")\n")
- v, _ := p.log[int(key)]
+ v := p.log[int(key)]
return v, nil
}
diff --git a/tutorial/go/src/main.go b/tutorial/go/src/main.go
index afac6bb..2b6f230 100644
--- a/tutorial/go/src/main.go
+++ b/tutorial/go/src/main.go
@@ -20,6 +20,7 @@
*/
import (
+ "crypto/tls"
"flag"
"fmt"
"os"
@@ -47,13 +48,13 @@
var protocolFactory thrift.TProtocolFactory
switch *protocol {
case "compact":
- protocolFactory = thrift.NewTCompactProtocolFactory()
+ protocolFactory = thrift.NewTCompactProtocolFactoryConf(nil)
case "simplejson":
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
+ protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(nil)
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
- protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
+ protocolFactory = thrift.NewTBinaryProtocolFactoryConf(nil)
default:
fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
Usage()
@@ -61,6 +62,11 @@
}
var transportFactory thrift.TTransportFactory
+ cfg := &thrift.TConfiguration{
+ TLSConfig: &tls.Config{
+ InsecureSkipVerify: true,
+ },
+ }
if *buffered {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
@@ -68,7 +74,7 @@
}
if *framed {
- transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
+ transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, cfg)
}
if *server {
@@ -76,7 +82,7 @@
fmt.Println("error running server:", err)
}
} else {
- if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
+ if err := runClient(transportFactory, protocolFactory, *addr, *secure, cfg); err != nil {
fmt.Println("error running client:", err)
}
}