summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYuxuan 'fishy' Wang <yuxuan.wang@reddit.com>2021-08-26 11:04:27 -0700
committerYuxuan 'fishy' Wang <fishywang@gmail.com>2021-08-27 09:28:08 -0700
commit17373a3f357cc81ab03fd02c316ad66b9c5ea260 (patch)
tree4bcbd85f46ce2fc1cf35e93ea7c6d79f3f55074b /lib
parentd53f056427a093f782c234d6dff85881cff0f5fb (diff)
downloadthrift-17373a3f357cc81ab03fd02c316ad66b9c5ea260.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/go/test/tests/client_error_test.go4
-rw-r--r--lib/go/test/tests/multiplexed_protocol_test.go32
-rw-r--r--lib/go/test/tests/one_way_test.go8
-rw-r--r--lib/go/test/tests/protocols_test.go80
-rw-r--r--lib/go/test/tests/struct_args_rets_test.go4
-rw-r--r--lib/go/test/tests/thrifttest_driver.go4
-rw-r--r--lib/go/thrift/application_exception.go3
-rw-r--r--lib/go/thrift/compact_protocol.go23
-rw-r--r--lib/go/thrift/framed_transport.go2
-rw-r--r--lib/go/thrift/http_client.go12
-rw-r--r--lib/go/thrift/json_protocol.go38
-rw-r--r--lib/go/thrift/protocol.go2
-rw-r--r--lib/go/thrift/rich_transport_test.go12
-rw-r--r--lib/go/thrift/serializer_test.go15
-rw-r--r--lib/go/thrift/simple_json_protocol.go90
-rw-r--r--lib/go/thrift/ssl_socket.go14
-rw-r--r--lib/go/thrift/staticcheck.conf4
-rw-r--r--lib/go/thrift/transport_test.go9
18 files changed, 126 insertions, 230 deletions
diff --git a/lib/go/test/tests/client_error_test.go b/lib/go/test/tests/client_error_test.go
index 64339dcf6..385f6f593 100644
--- a/lib/go/test/tests/client_error_test.go
+++ b/lib/go/test/tests/client_error_test.go
@@ -406,7 +406,9 @@ func prepareClientCallReply(protocol *MockTProtocol, failAt int, failWith error)
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 @@ func prepareClientCallException(protocol *MockTProtocol, failAt int, failWith er
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 a5975b768..72f174ea1 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -51,8 +51,12 @@ func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
}
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 createTransport(addr net.Addr) (thrift.TTransport, error) {
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 @@ func TestMultiplexedProtocolFirst(t *testing.T) {
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 TestMultiplexedProtocolFirst(t *testing.T) {
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 @@ func TestMultiplexedProtocolSecond(t *testing.T) {
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 TestMultiplexedProtocolSecond(t *testing.T) {
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 @@ func TestMultiplexedProtocolLegacy(t *testing.T) {
}
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 @@ func TestMultiplexedProtocolLegacy(t *testing.T) {
}
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 295dc1f5b..666181223 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -66,8 +66,12 @@ func TestInitOneway(t *testing.T) {
}
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 351fe5964..d4b53f277 100644
--- a/lib/go/test/tests/protocols_test.go
+++ b/lib/go/test/tests/protocols_test.go
@@ -26,8 +26,11 @@ import (
"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 @@ func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
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 @@ func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
// 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 df6b7468c..1f3d0b263 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 @@ import (
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 b35129581..29ccd534f 100644
--- a/lib/go/test/tests/thrifttest_driver.go
+++ b/lib/go/test/tests/thrifttest_driver.go
@@ -66,7 +66,9 @@ func (p *ThriftTestDriver) Start() {
"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 @@ func (p *ThriftTestDriver) Start() {
}
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 32d5b0147..ed85a645c 100644
--- a/lib/go/thrift/application_exception.go
+++ b/lib/go/thrift/application_exception.go
@@ -145,6 +145,9 @@ func (p *tApplicationException) Read(ctx context.Context, iprot TProtocol) error
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 e0de07700..ff3999c0e 100644
--- a/lib/go/thrift/compact_protocol.go
+++ b/lib/go/thrift/compact_protocol.go
@@ -334,7 +334,8 @@ func (p *TCompactProtocol) WriteString(ctx context.Context, value string) error
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 @@ func (p *TCompactProtocol) int32ToZigzag(n int32) int32 {
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 @@ func (p *TCompactProtocol) zigzagToInt64(n int64) int64 {
// 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 f683e7f54..2156dd76f 100644
--- a/lib/go/thrift/framed_transport.go
+++ b/lib/go/thrift/framed_transport.go
@@ -200,7 +200,7 @@ func (p *TFramedTransport) readFrame() error {
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 15015864f..ce62c96a2 100644
--- a/lib/go/thrift/http_client.go
+++ b/lib/go/thrift/http_client.go
@@ -36,13 +36,11 @@ import (
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 98764fa88..d248ecfee 100644
--- a/lib/go/thrift/json_protocol.go
+++ b/lib/go/thrift/json_protocol.go
@@ -501,44 +501,6 @@ func (p *TJSONProtocol) ParseElemListBegin() (elemType TType, size int, e error)
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 4768c8f14..bd76bcc7d 100644
--- a/lib/go/thrift/protocol.go
+++ b/lib/go/thrift/protocol.go
@@ -174,7 +174,7 @@ func Skip(ctx context.Context, self TProtocol, fieldType TType, maxDepth int) (e
}
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 25c3fd5aa..c5169188c 100644
--- a/lib/go/thrift/rich_transport_test.go
+++ b/lib/go/thrift/rich_transport_test.go
@@ -62,17 +62,17 @@ func TestReadByte(t *testing.T) {
}
}
-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 2e37ea2b1..9d785f97f 100644
--- a/lib/go/thrift/serializer_test.go
+++ b/lib/go/thrift/serializer_test.go
@@ -213,20 +213,18 @@ func ProtocolTest2(t *testing.T, pf ProtocolFactory) {
}
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 TestSerializer(t *testing.T) {
},
)
}
-
}
func TestSerializerPoolAsync(t *testing.T) {
diff --git a/lib/go/thrift/simple_json_protocol.go b/lib/go/thrift/simple_json_protocol.go
index 4967532c5..c9c450b89 100644
--- a/lib/go/thrift/simple_json_protocol.go
+++ b/lib/go/thrift/simple_json_protocol.go
@@ -173,7 +173,6 @@ var (
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 @@ func init() {
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 @@ func (p *TSimpleJSONProtocol) ReadBool(ctx context.Context) (bool, error) {
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 @@ func (p *TSimpleJSONProtocol) ReadBool(ctx context.Context) (bool, error) {
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 @@ func (p *TSimpleJSONProtocol) readNonSignificantWhitespace() error {
case ' ', '\r', '\n', '\t':
p.reader.ReadByte()
continue
- default:
- break
}
break
}
@@ -1069,7 +1063,7 @@ func (p *TSimpleJSONProtocol) ParseObjectEnd() error {
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 @@ func (p *TSimpleJSONProtocol) ParseListEnd() error {
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 @@ func (p *TSimpleJSONProtocol) ParseListEnd() error {
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 @@ func (p *TSimpleJSONProtocol) readIfNull() (bool, error) {
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 @@ func (p *TSimpleJSONProtocol) readNumeric() (Numeric, error) {
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 cd711fffe..bee1097d4 100644
--- a/lib/go/thrift/ssl_socket.go
+++ b/lib/go/thrift/ssl_socket.go
@@ -42,18 +42,22 @@ type TSSLSocket struct {
//
// 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 @@ func NewTSSLSocket(hostPort string, cfg *tls.Config) (*TSSLSocket, error) {
TLSConfig: cfg,
noPropagation: true,
- })
+ }), nil
}
// Deprecated: Use NewTSSLSocketConf instead.
@@ -73,7 +77,7 @@ func NewTSSLSocketTimeout(hostPort string, cfg *tls.Config, connectTimeout, sock
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 000000000..2ffe850be
--- /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 01278038e..309cc2805 100644
--- a/lib/go/thrift/transport_test.go
+++ b/lib/go/thrift/transport_test.go
@@ -166,12 +166,3 @@ func FindAvailableTCPServerPort(startPort int) (net.Addr, error) {
}
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
-}