From b5d7e58d9481aa3a460d0926c43e02e47e51d62d Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Wed, 21 Oct 2020 15:41:49 +0200 Subject: [PATCH] all: apply golint fixes --- internal/inproc/conn.go | 1 - internal/inproc/inproc.go | 7 +------ msgio.go | 2 +- protocol.go | 7 ------- router.go | 2 +- security/null/null_test.go | 2 +- security/plain/plain.go | 10 +++++----- security/plain/plain_cxx_test.go | 4 ++++ security/plain/plain_test.go | 3 +-- security_test.go | 2 +- transport.go | 14 ++++++++++---- zmq4_pubsub_test.go | 4 ++-- zmq4_pushpull_test.go | 2 +- zmq4_routerdealer_test.go | 2 +- zmq4_test.go | 14 -------------- 15 files changed, 29 insertions(+), 47 deletions(-) diff --git a/internal/inproc/conn.go b/internal/inproc/conn.go index 0f65b2a..52a1aa0 100644 --- a/internal/inproc/conn.go +++ b/internal/inproc/conn.go @@ -58,7 +58,6 @@ func (c *conn) write(data []byte) (int, error) { case <-c.wdeadline.wait(): return n, timeoutError{} } - return n, nil } func (c *conn) Read(data []byte) (int, error) { diff --git a/internal/inproc/inproc.go b/internal/inproc/inproc.go index 212630e..8b0d6eb 100644 --- a/internal/inproc/inproc.go +++ b/internal/inproc/inproc.go @@ -171,7 +171,6 @@ func Dial(addr string) (net.Conn, error) { } mgr.cv.Wait() } - panic("unreachable") } // Addr represents an in-process "network" end-point address. @@ -179,11 +178,7 @@ type Addr string // String implements net.Addr.String func (a Addr) String() string { - s := string(a) - if strings.HasPrefix(s, "inproc://") { - s = s[len("inproc://"):] - } - return s + return strings.TrimPrefix(string(a), "inproc://") } // Network returns the name of the network. diff --git a/msgio.go b/msgio.go index 4d144c6..c9b868c 100644 --- a/msgio.go +++ b/msgio.go @@ -167,7 +167,7 @@ func (mw *mwriter) rmConn(w *Conn) { func (w *mwriter) write(ctx context.Context, msg Msg) error { w.sem.lock() - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) w.mu.Lock() for i := range w.ws { ww := w.ws[i] diff --git a/protocol.go b/protocol.go index 1fb176c..e647a4b 100644 --- a/protocol.go +++ b/protocol.go @@ -61,13 +61,6 @@ func asString(slice []byte) string { return string(slice[:i]) } -func asByte(b bool) byte { - if b { - return 0x01 - } - return 0x00 -} - func asBool(b byte) (bool, error) { switch b { case 0x00: diff --git a/router.go b/router.go index 987e6c5..b0175c9 100644 --- a/router.go +++ b/router.go @@ -225,7 +225,7 @@ func (mw *routerMWriter) rmConn(w *Conn) { func (w *routerMWriter) write(ctx context.Context, msg Msg) error { w.sem.lock() - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) w.mu.Lock() id := msg.Frames[0] dmsg := NewMsgFrom(msg.Frames[1:]...) diff --git a/security/null/null_test.go b/security/null/null_test.go index cf8f674..4115a43 100644 --- a/security/null/null_test.go +++ b/security/null/null_test.go @@ -64,7 +64,7 @@ func TestHandshakeReqRep(t *testing.T) { rep := zmq4.NewRep(ctx, zmq4.WithSecurity(sec)) defer rep.Close() - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := rep.Listen(ep) if err != nil { diff --git a/security/plain/plain.go b/security/plain/plain.go index 121c972..e6d6651 100644 --- a/security/plain/plain.go +++ b/security/plain/plain.go @@ -50,7 +50,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error { // FIXME(sbinet): perform a real authentication err = validateHello(cmd.Body) if err != nil { - conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason + _ = conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason return fmt.Errorf("security/plain: could not authenticate client: %w", err) } @@ -71,7 +71,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error { raw, err := conn.Meta.MarshalZMTP() if err != nil { - conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason + _ = conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason return fmt.Errorf("security/plain: could not serialize metadata: %w", err) } @@ -97,13 +97,13 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error { return fmt.Errorf("security/plain: could not receive WELCOME from server: %w", err) } if cmd.Name != zmq4.CmdWelcome { - conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason + _ = conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason return fmt.Errorf("security/plain: expected a WELCOME command from server: %w", err) } raw, err := conn.Meta.MarshalZMTP() if err != nil { - conn.SendCmd(zmq4.CmdError, []byte("internal error")) // FIXME(sbinet) correct ERROR reason + _ = conn.SendCmd(zmq4.CmdError, []byte("internal error")) // FIXME(sbinet) correct ERROR reason return fmt.Errorf("security/plain: could not serialize metadata: %w", err) } @@ -117,7 +117,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error { return fmt.Errorf("security/plain: could not receive READY from server: %w", err) } if cmd.Name != zmq4.CmdReady { - conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason + _ = conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason return fmt.Errorf("security/plain: expected a READY command from server: %w", err) } diff --git a/security/plain/plain_cxx_test.go b/security/plain/plain_cxx_test.go index 6a35ecd..b416588 100644 --- a/security/plain/plain_cxx_test.go +++ b/security/plain/plain_cxx_test.go @@ -20,6 +20,10 @@ import ( "golang.org/x/sync/errgroup" ) +var ( + repQuit = zmq4.NewMsgString("bye") +) + func TestMain(m *testing.M) { auth := czmq4.NewAuth() diff --git a/security/plain/plain_test.go b/security/plain/plain_test.go index c9a8ef9..15004ae 100644 --- a/security/plain/plain_test.go +++ b/security/plain/plain_test.go @@ -22,7 +22,6 @@ import ( var ( reqQuit = zmq4.NewMsgString("QUIT") - repQuit = zmq4.NewMsgString("bye") ) func TestSecurity(t *testing.T) { @@ -68,7 +67,7 @@ func TestHandshakeReqRep(t *testing.T) { rep := zmq4.NewRep(ctx, zmq4.WithSecurity(sec)) defer rep.Close() - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := rep.Listen(ep) if err != nil { diff --git a/security_test.go b/security_test.go index 9a7d64b..f293b1d 100644 --- a/security_test.go +++ b/security_test.go @@ -62,7 +62,7 @@ func TestNullHandshakeReqRep(t *testing.T) { rep := NewRep(ctx, WithSecurity(sec), WithLogger(Devnull)) defer rep.Close() - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := rep.Listen(ep) if err != nil { diff --git a/transport.go b/transport.go index 4a86e67..8bf3e67 100644 --- a/transport.go +++ b/transport.go @@ -65,8 +65,14 @@ var drivers = transports{ } func init() { - RegisterTransport("ipc", transport.New("unix")) - RegisterTransport("tcp", transport.New("tcp")) - RegisterTransport("udp", transport.New("udp")) - RegisterTransport("inproc", inproc.Transport{}) + must := func(err error) { + if err != nil { + panic(fmt.Errorf("%+v", err)) + } + } + + must(RegisterTransport("ipc", transport.New("unix"))) + must(RegisterTransport("tcp", transport.New("tcp"))) + must(RegisterTransport("udp", transport.New("udp"))) + must(RegisterTransport("inproc", inproc.Transport{})) } diff --git a/zmq4_pubsub_test.go b/zmq4_pubsub_test.go index 874a166..c2c0e2e 100644 --- a/zmq4_pubsub_test.go +++ b/zmq4_pubsub_test.go @@ -123,7 +123,7 @@ func TestPubSub(t *testing.T) { wg1.Add(len(subs)) wg2.Add(len(subs)) - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := tc.pub.Listen(ep) @@ -225,7 +225,7 @@ func TestPubSubClosedSub(t *testing.T) { const nmsgs = 100 // the number of messages do not matter - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := pub.Listen(ep) if err != nil { diff --git a/zmq4_pushpull_test.go b/zmq4_pushpull_test.go index 6af0027..7890f92 100644 --- a/zmq4_pushpull_test.go +++ b/zmq4_pushpull_test.go @@ -69,7 +69,7 @@ func TestPushPull(t *testing.T) { ctx, timeout := context.WithTimeout(context.Background(), 20*time.Second) defer timeout() - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := tc.push.Listen(ep) diff --git a/zmq4_routerdealer_test.go b/zmq4_routerdealer_test.go index cab9ba2..35622ce 100644 --- a/zmq4_routerdealer_test.go +++ b/zmq4_routerdealer_test.go @@ -125,7 +125,7 @@ func TestRouterDealer(t *testing.T) { var seenMu sync.RWMutex seen := make(map[string]int) - grp, ctx := errgroup.WithContext(ctx) + grp, _ := errgroup.WithContext(ctx) grp.Go(func() error { err := router.Listen(ep) diff --git a/zmq4_test.go b/zmq4_test.go index 453604f..03dcba4 100644 --- a/zmq4_test.go +++ b/zmq4_test.go @@ -12,7 +12,6 @@ import ( "log" "net" "os" - "strconv" "strings" ) @@ -49,19 +48,6 @@ func EndPoint(transport string) (string, error) { } } -func getTCPPort() (string, error) { - addr, err := net.ResolveTCPAddr("tcp", "localhost:0") - if err != nil { - return "", err - } - l, err := net.ListenTCP("tcp", addr) - if err != nil { - return "", err - } - defer l.Close() - return strconv.Itoa(l.Addr().(*net.TCPAddr).Port), nil -} - func cleanUp(ep string) { switch { case strings.HasPrefix(ep, "ipc://"):