all: apply golint fixes

This commit is contained in:
Sebastien Binet 2020-10-21 15:41:49 +02:00
parent 14db8f5738
commit b5d7e58d94
15 changed files with 29 additions and 47 deletions

View file

@ -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) {

View file

@ -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.

View file

@ -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]

View file

@ -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:

View file

@ -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:]...)

View file

@ -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 {

View file

@ -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)
}

View file

@ -20,6 +20,10 @@ import (
"golang.org/x/sync/errgroup"
)
var (
repQuit = zmq4.NewMsgString("bye")
)
func TestMain(m *testing.M) {
auth := czmq4.NewAuth()

View file

@ -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 {

View file

@ -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 {

View file

@ -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{}))
}

View file

@ -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 {

View file

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

View file

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

View file

@ -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://"):