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/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),
+ )
}