lint fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-09-30 21:13:13 +03:00
parent 7b2e3cc8aa
commit 3247d144a8
14 changed files with 62 additions and 46 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/unistack-org/micro/v3/server" "github.com/unistack-org/micro/v3/server"
) )
// nolint: revive
// Api interface // Api interface
type Api interface { type Api interface {
// Initialise options // Initialise options

View File

@ -267,7 +267,7 @@ func Transport(t transport.Transport) Option {
func Register(r register.Register) Option { func Register(r register.Register) Option {
return func(o *Options) { return func(o *Options) {
if o.Router != nil { 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. // already set. Required for Init call below.
// set the transport tls // set the transport tls
o.Transport.Init( _ = o.Transport.Init(
transport.TLSConfig(t), transport.TLSConfig(t),
) )
} }

View File

@ -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]) w.opts.Logger.Tracef(nctx, "will be executed %v", steps[idx][nidx])
} }
cstep := steps[idx][nidx] cstep := steps[idx][nidx]
// nolint: nestif
if len(cstep.Requires()) == 0 { if len(cstep.Requires()) == 0 {
wg.Add(1) wg.Add(1)
go func(step Step) { go func(step Step) {

View File

@ -16,12 +16,14 @@ func TestMemoryTransport(t *testing.T) {
} }
defer l.Close() defer l.Close()
cherr := make(chan error, 1)
// accept // accept
go func() { go func() {
if err := l.Accept(func(sock Socket) { if nerr := l.Accept(func(sock Socket) {
for { for {
var m Message var m Message
if err := sock.Recv(&m); err != nil { if rerr := sock.Recv(&m); rerr != nil {
cherr <- rerr
return return
} }
if len(os.Getenv("INTEGRATION_TESTS")) == 0 { if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
@ -30,11 +32,12 @@ func TestMemoryTransport(t *testing.T) {
if cerr := sock.Send(&Message{ if cerr := sock.Send(&Message{
Body: []byte(`pong`), Body: []byte(`pong`),
}); cerr != nil { }); cerr != nil {
cherr <- cerr
return return
} }
} }
}); err != nil { }); nerr != nil {
t.Fatalf("Unexpected error accepting %v", err) cherr <- err
} }
}() }()
@ -45,19 +48,24 @@ func TestMemoryTransport(t *testing.T) {
} }
defer c.Close() defer c.Close()
// send <=> receive select {
for i := 0; i < 3; i++ { case err := <-cherr:
if err := c.Send(&Message{ t.Fatal(err)
Body: []byte(`ping`), default:
}); err != nil { // send <=> receive
return for i := 0; i < 3; i++ {
} if err := c.Send(&Message{
var m Message Body: []byte(`ping`),
if err := c.Recv(&m); err != nil { }); err != nil {
return return
} }
if len(os.Getenv("INTEGRATION_TESTS")) == 0 { var m Message
t.Logf("Client Received %s", string(m.Body)) if err := c.Recv(&m); err != nil {
return
}
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
t.Logf("Client Received %s", string(m.Body))
}
} }
} }
} }

View File

@ -34,9 +34,9 @@ type tunBatchSubscriber struct {
} }
type tunEvent struct { type tunEvent struct {
err error
message *broker.Message message *broker.Message
topic string topic string
err error
} }
// used to access tunnel from options context // used to access tunnel from options context
@ -199,7 +199,9 @@ func (t *tunBatchSubscriber) run() {
}, },
}} }}
// handle the message // handle the message
go t.handler(evts) go func() {
_ = t.handler(evts)
}()
} }
} }
@ -235,13 +237,15 @@ func (t *tunSubscriber) run() {
c.Close() c.Close()
// handle the message // handle the message
go t.handler(&tunEvent{ go func() {
topic: t.topic, _ = t.handler(&tunEvent{
message: &broker.Message{ topic: t.topic,
Header: m.Header, message: &broker.Message{
Body: m.Body, Header: m.Header,
}, Body: m.Body,
}) },
})
}()
} }
} }

View File

@ -37,7 +37,7 @@ func (t *tunTransport) Init(opts ...transport.Option) error {
// get the transport // get the transport
tr, ok := t.options.Context.Value(transportKey{}).(transport.Transport) tr, ok := t.options.Context.Value(transportKey{}).(transport.Transport)
if ok { if ok {
tun.Init(tunnel.Transport(tr)) _ = tun.Init(tunnel.Transport(tr))
} }
// set the tunnel // set the tunnel

View File

@ -11,6 +11,7 @@ import (
"github.com/unistack-org/micro/v3/resolver" "github.com/unistack-org/micro/v3/resolver"
) )
// nolint: golint,revive
// HTTPResolver is a HTTP network resolver // HTTPResolver is a HTTP network resolver
type HTTPResolver struct { type HTTPResolver struct {
// Proto if not set, defaults to http // Proto if not set, defaults to http
@ -53,6 +54,7 @@ func (r *HTTPResolver) Resolve(name string) ([]*resolver.Record, error) {
q.Set("name", name) q.Set("name", name)
uri.RawQuery = q.Encode() uri.RawQuery = q.Encode()
// nolint: noctx
rsp, err := http.Get(uri.String()) rsp, err := http.Get(uri.String())
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -16,15 +16,15 @@ type Options struct {
Name string Name string
Gateway string Gateway string
Network string Network string
Id string ID string
Address string Address string
Precache bool Precache bool
} }
// Id sets Router Id // ID sets Router Id
func Id(id string) Option { func ID(id string) Option {
return func(o *Options) { return func(o *Options) {
o.Id = id o.ID = id
} }
} }
@ -80,7 +80,7 @@ func Name(n string) Option {
// NewOptions returns router default options // NewOptions returns router default options
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Id: id.Must(), ID: id.Must(),
Network: DefaultNetwork, Network: DefaultNetwork,
Register: register.DefaultRegister, Register: register.DefaultRegister,
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,

View File

@ -262,7 +262,7 @@ func TLSConfig(t *tls.Config) Option {
// already set. Required for Init call below. // already set. Required for Init call below.
// set the transport tls // set the transport tls
o.Transport.Init( _ = o.Transport.Init(
transport.TLSConfig(t), transport.TLSConfig(t),
) )
} }

View File

@ -48,7 +48,7 @@ func Verify(a auth.Auth) error {
} }
// set the credentials and token in auth options // set the credentials and token in auth options
a.Init( _ = a.Init(
auth.ClientToken(token), auth.ClientToken(token),
auth.Credentials(accID, accSecret), auth.Credentials(accID, accSecret),
) )
@ -79,7 +79,7 @@ func Verify(a auth.Auth) error {
} }
// set the token // set the token
a.Init(auth.ClientToken(tok)) _ = a.Init(auth.ClientToken(tok))
} }
}() }()

View File

@ -49,7 +49,7 @@ func (p *poolConn) Close() error {
return nil return nil
} }
func (p *poolConn) Id() string { func (p *poolConn) ID() string {
return p.id return p.id
} }

View File

@ -21,7 +21,7 @@ type Pool interface {
// Conn conn pool interface // Conn conn pool interface
type Conn interface { type Conn interface {
// unique id of connection // unique id of connection
Id() string ID() string
// time it was created // time it was created
Created() time.Time Created() time.Time
// embedded connection // embedded connection

View File

@ -82,9 +82,9 @@ func getValueByName(v reflect.Value, key string) (reflect.Value, error) {
case reflect.Struct: case reflect.Struct:
value = v.FieldByName(key) value = v.FieldByName(key)
case reflect.Map: case reflect.Map:
kValue := reflect.Indirect(reflect.New(v.Type().Key())) kvalue := reflect.Indirect(reflect.New(v.Type().Key()))
kValue.SetString(key) kvalue.SetString(key)
value = v.MapIndex(kValue) value = v.MapIndex(kvalue)
} }
if !value.IsValid() { if !value.IsValid() {

View File

@ -28,8 +28,8 @@ type Stream struct {
Entries chan *Entry Entries chan *Entry
// Stop channel // Stop channel
Stop chan bool Stop chan bool
// Id of the stream // ID of the stream
Id string ID string
} }
// Put adds a new value to ring buffer // Put adds a new value to ring buffer
@ -53,7 +53,7 @@ func (b *Buffer) Put(v interface{}) {
for _, stream := range b.streams { for _, stream := range b.streams {
select { select {
case <-stream.Stop: case <-stream.Stop:
delete(b.streams, stream.Id) delete(b.streams, stream.ID)
close(stream.Entries) close(stream.Entries)
case stream.Entries <- entry: case stream.Entries <- entry:
} }
@ -116,7 +116,7 @@ func (b *Buffer) Stream() (<-chan *Entry, chan bool) {
stop := make(chan bool) stop := make(chan bool)
b.streams[id] = &Stream{ b.streams[id] = &Stream{
Id: id, ID: id,
Entries: entries, Entries: entries,
Stop: stop, Stop: stop,
} }