From 7b2e3cc8aa511fcf8fbec66e1ede4ea5c79dd787 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 30 Sep 2021 21:00:02 +0300 Subject: [PATCH] lint fixes Signed-off-by: Vasiliy Tolstov --- api/api.go | 10 +++++----- broker/memory.go | 3 +-- broker/memory_test.go | 4 ++-- client/options.go | 40 ++++++++++++++++++++-------------------- codec/codec.go | 2 +- errors/errors.go | 30 +++++++++++++++--------------- errors/errors_test.go | 12 ++++++------ flow/default.go | 4 ++-- flow/options.go | 6 +++--- network/options.go | 12 ++++++------ router/watcher.go | 4 ++-- server/errors_test.go | 2 +- sync/memory.go | 2 +- util/qson/qson.go | 2 +- util/sync/options.go | 2 ++ 15 files changed, 68 insertions(+), 67 deletions(-) diff --git a/api/api.go b/api/api.go index f47f889a..4caeae12 100644 --- a/api/api.go +++ b/api/api.go @@ -125,14 +125,14 @@ func Validate(e *Endpoint) error { ps := p[0] pe := p[len(p)-1] - if ps == '^' && pe == '$' { - _, err := regexp.CompilePOSIX(p) - if err != nil { + switch { + case ps == '^' && pe == '$': + if _, err := regexp.CompilePOSIX(p); err != nil { return err } - } else if ps == '^' && pe != '$' { + case ps == '^' && pe != '$': return errors.New("invalid path") - } else if ps != '^' && pe == '$' { + case ps != '^' && pe == '$': return errors.New("invalid path") } } diff --git a/broker/memory.go b/broker/memory.go index 1ae2e8ad..3e2888bb 100644 --- a/broker/memory.go +++ b/broker/memory.go @@ -122,11 +122,10 @@ func (m *memoryBroker) publish(ctx context.Context, msgs []*Message, opts ...Pub p.message = v.Body } else { p.topic, _ = v.Header.Get(metadata.HeaderTopic) - buf, err := m.opts.Codec.Marshal(v) + p.message, err = m.opts.Codec.Marshal(v) if err != nil { return err } - p.message = buf } msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p) } diff --git a/broker/memory_test.go b/broker/memory_test.go index fed2b8d3..ab0eca76 100644 --- a/broker/memory_test.go +++ b/broker/memory_test.go @@ -28,7 +28,7 @@ func TestMemoryBatchBroker(t *testing.T) { t.Fatalf("Unexpected error subscribing %v", err) } - msgs := make([]*Message, 0, 0) + msgs := make([]*Message, 0, count) for i := 0; i < count; i++ { message := &Message{ Header: map[string]string{ @@ -74,7 +74,7 @@ func TestMemoryBroker(t *testing.T) { t.Fatalf("Unexpected error subscribing %v", err) } - msgs := make([]*Message, 0, 0) + msgs := make([]*Message, 0, count) for i := 0; i < count; i++ { message := &Message{ Header: map[string]string{ diff --git a/client/options.go b/client/options.go index 1a6a996f..a74affd6 100644 --- a/client/options.go +++ b/client/options.go @@ -19,8 +19,8 @@ import ( // Options holds client options type Options struct { - // Router used to get route - Router router.Router + // Transport used for transfer messages + Transport transport.Transport // Selector used to select needed address Selector selector.Selector // Logger used to log messages @@ -31,18 +31,16 @@ type Options struct { Broker broker.Broker // Meter used for metrics Meter meter.Meter - // Transport used for transfer messages - Transport transport.Transport // Context is used for external options Context context.Context + // Router used to get route + Router router.Router + // TLSConfig specifies tls.Config for secure connection + TLSConfig *tls.Config // Codecs map Codecs map[string]codec.Codec // Lookup func used to get destination addr Lookup LookupFunc - // TLSConfig specifies tls.Config for secure connection - TLSConfig *tls.Config - // CallOptions contains default CallOptions - CallOptions CallOptions // Proxy is used for proxy requests Proxy string // ContentType is used to select codec @@ -51,6 +49,8 @@ type Options struct { Name string // Wrappers contains wrappers Wrappers []Wrapper + // CallOptions contains default CallOptions + CallOptions CallOptions // PoolSize connection pool size PoolSize int // PoolTTL connection pool ttl @@ -68,12 +68,12 @@ func NewCallOptions(opts ...CallOption) CallOptions { // CallOptions holds client call options type CallOptions struct { - // Router used for route - Router router.Router // Selector selects addr Selector selector.Selector // Context used for deadline Context context.Context + // Router used for route + Router router.Router // Retry func used for retries Retry RetryFunc // Backoff func used for backoff when retry @@ -82,22 +82,22 @@ type CallOptions struct { Network string // Content-Type ContentType string - // CallWrappers call wrappers - CallWrappers []CallWrapper - // SelectOptions selector options - SelectOptions []selector.SelectOption + // AuthToken string + AuthToken string // Address specifies static addr list Address []string - // Retries specifies retries num - Retries int + // SelectOptions selector options + SelectOptions []selector.SelectOption + // CallWrappers call wrappers + CallWrappers []CallWrapper // StreamTimeout stream timeout StreamTimeout time.Duration // RequestTimeout request timeout RequestTimeout time.Duration // DialTimeout dial timeout DialTimeout time.Duration - // AuthToken string - AuthToken string + // Retries specifies retries num + Retries int } // Context pass context to client @@ -118,12 +118,12 @@ func NewPublishOptions(opts ...PublishOption) PublishOptions { // PublishOptions holds publish options type PublishOptions struct { - // BodyOnly will publish only message body - BodyOnly bool // Context used for external options Context context.Context // Exchange topic exchange name Exchange string + // BodyOnly will publish only message body + BodyOnly bool } // NewMessageOptions creates message options struct diff --git a/codec/codec.go b/codec/codec.go index dec2bce5..5449da18 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -58,7 +58,7 @@ type Message struct { Method string Endpoint string Error string - Id string + ID string Body []byte Type MessageType } diff --git a/errors/errors.go b/errors/errors.go index 924296e0..b5163036 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -37,8 +37,8 @@ var ( // Error type type Error struct { - // Id holds error id or service, usually someting like my_service or id - Id string + // ID holds error id or service, usually someting like my_service or id + ID string // Detail holds some useful details about error Detail string // Status usually holds text of http status @@ -56,7 +56,7 @@ func (e *Error) Error() string { // New generates a custom error func New(id, detail string, code int32) error { return &Error{ - Id: id, + ID: id, Code: code, Detail: detail, Status: http.StatusText(int(code)), @@ -77,7 +77,7 @@ func Parse(err string) *Error { // BadRequest generates a 400 error. func BadRequest(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 400, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(400), @@ -87,7 +87,7 @@ func BadRequest(id, format string, a ...interface{}) error { // Unauthorized generates a 401 error. func Unauthorized(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 401, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(401), @@ -97,7 +97,7 @@ func Unauthorized(id, format string, a ...interface{}) error { // Forbidden generates a 403 error. func Forbidden(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 403, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(403), @@ -107,7 +107,7 @@ func Forbidden(id, format string, a ...interface{}) error { // NotFound generates a 404 error. func NotFound(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 404, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(404), @@ -117,7 +117,7 @@ func NotFound(id, format string, a ...interface{}) error { // MethodNotAllowed generates a 405 error. func MethodNotAllowed(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 405, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(405), @@ -127,7 +127,7 @@ func MethodNotAllowed(id, format string, a ...interface{}) error { // Timeout generates a 408 error. func Timeout(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 408, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(408), @@ -137,7 +137,7 @@ func Timeout(id, format string, a ...interface{}) error { // Conflict generates a 409 error. func Conflict(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 409, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(409), @@ -147,7 +147,7 @@ func Conflict(id, format string, a ...interface{}) error { // InternalServerError generates a 500 error. func InternalServerError(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 500, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(500), @@ -157,7 +157,7 @@ func InternalServerError(id, format string, a ...interface{}) error { // NotImplemented generates a 501 error func NotImplemented(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 501, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(501), @@ -167,7 +167,7 @@ func NotImplemented(id, format string, a ...interface{}) error { // BadGateway generates a 502 error func BadGateway(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 502, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(502), @@ -177,7 +177,7 @@ func BadGateway(id, format string, a ...interface{}) error { // ServiceUnavailable generates a 503 error func ServiceUnavailable(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 503, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(503), @@ -187,7 +187,7 @@ func ServiceUnavailable(id, format string, a ...interface{}) error { // GatewayTimeout generates a 504 error func GatewayTimeout(id, format string, a ...interface{}) error { return &Error{ - Id: id, + ID: id, Code: 504, Detail: fmt.Sprintf(format, a...), Status: http.StatusText(504), diff --git a/errors/errors_test.go b/errors/errors_test.go index f57b0faa..a853f5c2 100644 --- a/errors/errors_test.go +++ b/errors/errors_test.go @@ -9,12 +9,12 @@ import ( func TestFromError(t *testing.T) { err := NotFound("go.micro.test", "%s", "example") merr := FromError(err) - if merr.Id != "go.micro.test" || merr.Code != 404 { + if merr.ID != "go.micro.test" || merr.Code != 404 { t.Fatalf("invalid conversation %v != %v", err, merr) } err = er.New(err.Error()) merr = FromError(err) - if merr.Id != "go.micro.test" || merr.Code != 404 { + if merr.ID != "go.micro.test" || merr.Code != 404 { t.Fatalf("invalid conversation %v != %v", err, merr) } } @@ -36,7 +36,7 @@ func TestEqual(t *testing.T) { func TestErrors(t *testing.T) { testData := []*Error{ { - Id: "test", + ID: "test", Code: 500, Detail: "Internal server error", Status: http.StatusText(500), @@ -44,7 +44,7 @@ func TestErrors(t *testing.T) { } for _, e := range testData { - ne := New(e.Id, e.Detail, e.Code) + ne := New(e.ID, e.Detail, e.Code) if e.Error() != ne.Error() { t.Fatalf("Expected %s got %s", e.Error(), ne.Error()) @@ -56,8 +56,8 @@ func TestErrors(t *testing.T) { t.Fatalf("Expected error got nil %v", pe) } - if pe.Id != e.Id { - t.Fatalf("Expected %s got %s", e.Id, pe.Id) + if pe.ID != e.ID { + t.Fatalf("Expected %s got %s", e.ID, pe.ID) } if pe.Detail != e.Detail { diff --git a/flow/default.go b/flow/default.go index 3132936c..642b63da 100644 --- a/flow/default.go +++ b/flow/default.go @@ -426,9 +426,9 @@ func (f *microFlow) WorkflowLoad(ctx context.Context, id string) (Workflow, erro type microCallStep struct { rsp *Message req *Message - opts StepOptions service string method string + opts StepOptions status Status } @@ -510,8 +510,8 @@ func (s *microCallStep) Execute(ctx context.Context, req *Message, opts ...Execu type microPublishStep struct { req *Message rsp *Message - opts StepOptions topic string + opts StepOptions status Status } diff --git a/flow/options.go b/flow/options.go index d44eb9ce..79688d07 100644 --- a/flow/options.go +++ b/flow/options.go @@ -96,8 +96,8 @@ type WorkflowOption func(*WorkflowOptions) // WorkflowOptions holds workflow options type WorkflowOptions struct { - ID string Context context.Context + ID string } // WorkflowID set workflow id @@ -193,10 +193,10 @@ func NewExecuteOptions(opts ...ExecuteOption) ExecuteOptions { } type StepOptions struct { - ID string Context context.Context - Requires []string Fallback string + ID string + Requires []string } type StepOption func(*StepOptions) diff --git a/network/options.go b/network/options.go index 91d337cb..2f0b12e5 100644 --- a/network/options.go +++ b/network/options.go @@ -27,8 +27,8 @@ type Options struct { Tracer tracer.Tracer // Tunnel used for transfer data Tunnel tunnel.Tunnel - // Id of the node - Id string + // ID of the node + ID string // Name of the network Name string // Address to bind to @@ -39,10 +39,10 @@ type Options struct { Nodes []string } -// Id sets the id of the network node -func Id(id string) Option { +// ID sets the id of the network node +func ID(id string) Option { return func(o *Options) { - o.Id = id + o.ID = id } } @@ -119,7 +119,7 @@ func Tracer(t tracer.Tracer) Option { // NewOptions returns network default options func NewOptions(opts ...Option) Options { options := Options{ - Id: id.Must(), + ID: id.Must(), Name: "go.micro", Address: ":0", Logger: logger.DefaultLogger, diff --git a/router/watcher.go b/router/watcher.go index 548a396c..3cde0761 100644 --- a/router/watcher.go +++ b/router/watcher.go @@ -38,8 +38,8 @@ func (t EventType) String() string { type Event struct { // Timestamp is event timestamp Timestamp time.Time - // Id of the event - Id string + // ID of the event + ID string // Route is table route Route Route // Type defines type of event diff --git a/server/errors_test.go b/server/errors_test.go index ffa3aa90..728b0ba0 100644 --- a/server/errors_test.go +++ b/server/errors_test.go @@ -13,7 +13,7 @@ func TestError(t *testing.T) { if !ok { t.Fatal("error not *errors.Error") } - if merr.Id != "svc1" { + if merr.ID != "svc1" { t.Fatal("id != svc1") } } diff --git a/sync/memory.go b/sync/memory.go index 8eb1ed95..2777e4d1 100644 --- a/sync/memory.go +++ b/sync/memory.go @@ -51,7 +51,7 @@ func (m *memorySync) Leader(id string, opts ...LeaderOption) (Leader, error) { id: id, resign: func(id string) error { once.Do(func() { - m.Unlock(id) + _ = m.Unlock(id) }) return nil }, diff --git a/util/qson/qson.go b/util/qson/qson.go index 711dac92..a7f85533 100644 --- a/util/qson/qson.go +++ b/util/qson/qson.go @@ -16,7 +16,7 @@ import ( var ( // ErrInvalidParam is returned when invalid data is provided to the ToJSON or Unmarshal function. // Specifically, this will be returned when there is no equals sign present in the URL query parameter. - ErrInvalidParam error = errors.New("qson: invalid url query param provided") + ErrInvalidParam = errors.New("qson: invalid url query param provided") bracketSplitter *regexp.Regexp ) diff --git a/util/sync/options.go b/util/sync/options.go index 0dcdb617..59482934 100644 --- a/util/sync/options.go +++ b/util/sync/options.go @@ -29,6 +29,7 @@ func Stores(stores ...store.Store) Option { } } +// nolint: golint,revive // SyncInterval sets the duration between syncs from L0 to L1 func SyncInterval(d time.Duration) Option { return func(o *Options) { @@ -36,6 +37,7 @@ func SyncInterval(d time.Duration) Option { } } +// nolint: golint,revive // SyncMultiplier sets the multiplication factor for time to wait each sync layer func SyncMultiplier(i int64) Option { return func(o *Options) {