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