From 3247d144a8be84ae3dae196f1db229bd98a4d712 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 30 Sep 2021 21:13:13 +0300 Subject: [PATCH] lint fixes Signed-off-by: Vasiliy Tolstov --- api/api.go | 1 + client/options.go | 4 +-- flow/default.go | 1 + network/transport/memory_test.go | 42 ++++++++++++++++----------- network/tunnel/broker/broker.go | 22 ++++++++------ network/tunnel/transport/transport.go | 2 +- resolver/http/http.go | 2 ++ router/options.go | 10 +++---- server/options.go | 2 +- util/auth/auth.go | 4 +-- util/pool/default.go | 2 +- util/pool/pool.go | 2 +- util/reflect/path.go | 6 ++-- util/ring/buffer.go | 8 ++--- 14 files changed, 62 insertions(+), 46 deletions(-) diff --git a/api/api.go b/api/api.go index 4caeae12..62d6c688 100644 --- a/api/api.go +++ b/api/api.go @@ -10,6 +10,7 @@ import ( "github.com/unistack-org/micro/v3/server" ) +// nolint: revive // Api interface type Api interface { // Initialise options diff --git a/client/options.go b/client/options.go index a74affd6..638436cc 100644 --- a/client/options.go +++ b/client/options.go @@ -267,7 +267,7 @@ func Transport(t transport.Transport) Option { func Register(r register.Register) Option { return func(o *Options) { if o.Router != nil { - o.Router.Init(router.Register(r)) + _ = o.Router.Init(router.Register(r)) } } } @@ -331,7 +331,7 @@ func TLSConfig(t *tls.Config) Option { // already set. Required for Init call below. // set the transport tls - o.Transport.Init( + _ = o.Transport.Init( transport.TLSConfig(t), ) } diff --git a/flow/default.go b/flow/default.go index 642b63da..85aab18d 100644 --- a/flow/default.go +++ b/flow/default.go @@ -241,6 +241,7 @@ func (w *microWorkflow) Execute(ctx context.Context, req *Message, opts ...Execu w.opts.Logger.Tracef(nctx, "will be executed %v", steps[idx][nidx]) } cstep := steps[idx][nidx] + // nolint: nestif if len(cstep.Requires()) == 0 { wg.Add(1) go func(step Step) { diff --git a/network/transport/memory_test.go b/network/transport/memory_test.go index 9bbd8b76..cf712b86 100644 --- a/network/transport/memory_test.go +++ b/network/transport/memory_test.go @@ -16,12 +16,14 @@ func TestMemoryTransport(t *testing.T) { } defer l.Close() + cherr := make(chan error, 1) // accept go func() { - if err := l.Accept(func(sock Socket) { + if nerr := l.Accept(func(sock Socket) { for { var m Message - if err := sock.Recv(&m); err != nil { + if rerr := sock.Recv(&m); rerr != nil { + cherr <- rerr return } if len(os.Getenv("INTEGRATION_TESTS")) == 0 { @@ -30,11 +32,12 @@ func TestMemoryTransport(t *testing.T) { if cerr := sock.Send(&Message{ Body: []byte(`pong`), }); cerr != nil { + cherr <- cerr return } } - }); err != nil { - t.Fatalf("Unexpected error accepting %v", err) + }); nerr != nil { + cherr <- err } }() @@ -45,19 +48,24 @@ func TestMemoryTransport(t *testing.T) { } defer c.Close() - // send <=> receive - for i := 0; i < 3; i++ { - if err := c.Send(&Message{ - Body: []byte(`ping`), - }); err != nil { - return - } - var m Message - if err := c.Recv(&m); err != nil { - return - } - if len(os.Getenv("INTEGRATION_TESTS")) == 0 { - t.Logf("Client Received %s", string(m.Body)) + select { + case err := <-cherr: + t.Fatal(err) + default: + // send <=> receive + for i := 0; i < 3; i++ { + if err := c.Send(&Message{ + Body: []byte(`ping`), + }); err != nil { + return + } + var m Message + if err := c.Recv(&m); err != nil { + return + } + if len(os.Getenv("INTEGRATION_TESTS")) == 0 { + t.Logf("Client Received %s", string(m.Body)) + } } } } diff --git a/network/tunnel/broker/broker.go b/network/tunnel/broker/broker.go index ddbe5a4d..bd06b28b 100644 --- a/network/tunnel/broker/broker.go +++ b/network/tunnel/broker/broker.go @@ -34,9 +34,9 @@ type tunBatchSubscriber struct { } type tunEvent struct { + err error message *broker.Message topic string - err error } // used to access tunnel from options context @@ -199,7 +199,9 @@ func (t *tunBatchSubscriber) run() { }, }} // handle the message - go t.handler(evts) + go func() { + _ = t.handler(evts) + }() } } @@ -235,13 +237,15 @@ func (t *tunSubscriber) run() { c.Close() // handle the message - go t.handler(&tunEvent{ - topic: t.topic, - message: &broker.Message{ - Header: m.Header, - Body: m.Body, - }, - }) + go func() { + _ = t.handler(&tunEvent{ + topic: t.topic, + message: &broker.Message{ + Header: m.Header, + Body: m.Body, + }, + }) + }() } } diff --git a/network/tunnel/transport/transport.go b/network/tunnel/transport/transport.go index ce24e0e8..6d59def3 100644 --- a/network/tunnel/transport/transport.go +++ b/network/tunnel/transport/transport.go @@ -37,7 +37,7 @@ func (t *tunTransport) Init(opts ...transport.Option) error { // get the transport tr, ok := t.options.Context.Value(transportKey{}).(transport.Transport) if ok { - tun.Init(tunnel.Transport(tr)) + _ = tun.Init(tunnel.Transport(tr)) } // set the tunnel diff --git a/resolver/http/http.go b/resolver/http/http.go index 0b862a2e..af64bbf7 100644 --- a/resolver/http/http.go +++ b/resolver/http/http.go @@ -11,6 +11,7 @@ import ( "github.com/unistack-org/micro/v3/resolver" ) +// nolint: golint,revive // HTTPResolver is a HTTP network resolver type HTTPResolver struct { // Proto if not set, defaults to http @@ -53,6 +54,7 @@ func (r *HTTPResolver) Resolve(name string) ([]*resolver.Record, error) { q.Set("name", name) uri.RawQuery = q.Encode() + // nolint: noctx rsp, err := http.Get(uri.String()) if err != nil { return nil, err diff --git a/router/options.go b/router/options.go index 42b2b45f..7241e387 100644 --- a/router/options.go +++ b/router/options.go @@ -16,15 +16,15 @@ type Options struct { Name string Gateway string Network string - Id string + ID string Address string Precache bool } -// Id sets Router Id -func Id(id string) Option { +// ID sets Router Id +func ID(id string) Option { return func(o *Options) { - o.Id = id + o.ID = id } } @@ -80,7 +80,7 @@ func Name(n string) Option { // NewOptions returns router default options func NewOptions(opts ...Option) Options { options := Options{ - Id: id.Must(), + ID: id.Must(), Network: DefaultNetwork, Register: register.DefaultRegister, Logger: logger.DefaultLogger, diff --git a/server/options.go b/server/options.go index 0224a9e8..93daafc1 100644 --- a/server/options.go +++ b/server/options.go @@ -262,7 +262,7 @@ func TLSConfig(t *tls.Config) Option { // already set. Required for Init call below. // set the transport tls - o.Transport.Init( + _ = o.Transport.Init( transport.TLSConfig(t), ) } diff --git a/util/auth/auth.go b/util/auth/auth.go index b3889403..e6bf18c7 100644 --- a/util/auth/auth.go +++ b/util/auth/auth.go @@ -48,7 +48,7 @@ func Verify(a auth.Auth) error { } // set the credentials and token in auth options - a.Init( + _ = a.Init( auth.ClientToken(token), auth.Credentials(accID, accSecret), ) @@ -79,7 +79,7 @@ func Verify(a auth.Auth) error { } // set the token - a.Init(auth.ClientToken(tok)) + _ = a.Init(auth.ClientToken(tok)) } }() diff --git a/util/pool/default.go b/util/pool/default.go index f8ff2ae4..deada016 100644 --- a/util/pool/default.go +++ b/util/pool/default.go @@ -49,7 +49,7 @@ func (p *poolConn) Close() error { return nil } -func (p *poolConn) Id() string { +func (p *poolConn) ID() string { return p.id } diff --git a/util/pool/pool.go b/util/pool/pool.go index d9b05bb3..ebd28921 100644 --- a/util/pool/pool.go +++ b/util/pool/pool.go @@ -21,7 +21,7 @@ type Pool interface { // Conn conn pool interface type Conn interface { // unique id of connection - Id() string + ID() string // time it was created Created() time.Time // embedded connection diff --git a/util/reflect/path.go b/util/reflect/path.go index 902add63..7a3814dd 100644 --- a/util/reflect/path.go +++ b/util/reflect/path.go @@ -82,9 +82,9 @@ func getValueByName(v reflect.Value, key string) (reflect.Value, error) { case reflect.Struct: value = v.FieldByName(key) case reflect.Map: - kValue := reflect.Indirect(reflect.New(v.Type().Key())) - kValue.SetString(key) - value = v.MapIndex(kValue) + kvalue := reflect.Indirect(reflect.New(v.Type().Key())) + kvalue.SetString(key) + value = v.MapIndex(kvalue) } if !value.IsValid() { diff --git a/util/ring/buffer.go b/util/ring/buffer.go index c3cbd07c..81d341d5 100644 --- a/util/ring/buffer.go +++ b/util/ring/buffer.go @@ -28,8 +28,8 @@ type Stream struct { Entries chan *Entry // Stop channel Stop chan bool - // Id of the stream - Id string + // ID of the stream + ID string } // Put adds a new value to ring buffer @@ -53,7 +53,7 @@ func (b *Buffer) Put(v interface{}) { for _, stream := range b.streams { select { case <-stream.Stop: - delete(b.streams, stream.Id) + delete(b.streams, stream.ID) close(stream.Entries) case stream.Entries <- entry: } @@ -116,7 +116,7 @@ func (b *Buffer) Stream() (<-chan *Entry, chan bool) { stop := make(chan bool) b.streams[id] = &Stream{ - Id: id, + ID: id, Entries: entries, Stop: stop, }