diff options
author | Yuxuan 'fishy' Wang <yuxuan.wang@reddit.com> | 2021-08-26 11:04:27 -0700 |
---|---|---|
committer | Yuxuan 'fishy' Wang <fishywang@gmail.com> | 2021-08-27 09:28:08 -0700 |
commit | 17373a3f357cc81ab03fd02c316ad66b9c5ea260 (patch) | |
tree | 4bcbd85f46ce2fc1cf35e93ea7c6d79f3f55074b /tutorial | |
parent | d53f056427a093f782c234d6dff85881cff0f5fb (diff) | |
download | thrift-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 'tutorial')
-rw-r--r-- | tutorial/go/src/client.go | 16 | ||||
-rw-r--r-- | tutorial/go/src/handler.go | 6 | ||||
-rw-r--r-- | tutorial/go/src/main.go | 16 |
3 files changed, 16 insertions, 22 deletions
diff --git a/tutorial/go/src/client.go b/tutorial/go/src/client.go index 8776f9c0e..f944cf8a6 100644 --- a/tutorial/go/src/client.go +++ b/tutorial/go/src/client.go @@ -21,7 +21,6 @@ package main import ( "context" - "crypto/tls" "fmt" "github.com/apache/thrift/lib/go/thrift" @@ -79,21 +78,14 @@ func handleClient(client *tutorial.CalculatorClient) (err error) { 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 7645fc2a5..a9edd264a 100644 --- a/tutorial/go/src/handler.go +++ b/tutorial/go/src/handler.go @@ -51,13 +51,10 @@ func (p *CalculatorHandler) Calculate(ctx context.Context, logid int32, w *tutor 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 @@ func (p *CalculatorHandler) Calculate(ctx context.Context, logid int32, w *tutor return } val = w.Num1 / w.Num2 - break default: ouch := tutorial.NewInvalidOperation() ouch.WhatOp = int32(w.Op) @@ -93,7 +89,7 @@ func (p *CalculatorHandler) Calculate(ctx context.Context, logid int32, w *tutor 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 afac6bba7..2b6f230f5 100644 --- a/tutorial/go/src/main.go +++ b/tutorial/go/src/main.go @@ -20,6 +20,7 @@ package main */ import ( + "crypto/tls" "flag" "fmt" "os" @@ -47,13 +48,13 @@ func main() { 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 @@ func main() { } var transportFactory thrift.TTransportFactory + cfg := &thrift.TConfiguration{ + TLSConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + } if *buffered { transportFactory = thrift.NewTBufferedTransportFactory(8192) } else { @@ -68,7 +74,7 @@ func main() { } if *framed { - transportFactory = thrift.NewTFramedTransportFactory(transportFactory) + transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, cfg) } if *server { @@ -76,7 +82,7 @@ func main() { 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) } } |