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/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)