lint fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-09-30 21:00:02 +03:00
parent 8688179acd
commit 7b2e3cc8aa
15 changed files with 68 additions and 67 deletions

View File

@ -125,14 +125,14 @@ func Validate(e *Endpoint) error {
ps := p[0] ps := p[0]
pe := p[len(p)-1] pe := p[len(p)-1]
if ps == '^' && pe == '$' { switch {
_, err := regexp.CompilePOSIX(p) case ps == '^' && pe == '$':
if err != nil { if _, err := regexp.CompilePOSIX(p); err != nil {
return err return err
} }
} else if ps == '^' && pe != '$' { case ps == '^' && pe != '$':
return errors.New("invalid path") return errors.New("invalid path")
} else if ps != '^' && pe == '$' { case ps != '^' && pe == '$':
return errors.New("invalid path") return errors.New("invalid path")
} }
} }

View File

@ -122,11 +122,10 @@ func (m *memoryBroker) publish(ctx context.Context, msgs []*Message, opts ...Pub
p.message = v.Body p.message = v.Body
} else { } else {
p.topic, _ = v.Header.Get(metadata.HeaderTopic) 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 { if err != nil {
return err return err
} }
p.message = buf
} }
msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p) msgTopicMap[p.topic] = append(msgTopicMap[p.topic], p)
} }

View File

@ -28,7 +28,7 @@ func TestMemoryBatchBroker(t *testing.T) {
t.Fatalf("Unexpected error subscribing %v", err) t.Fatalf("Unexpected error subscribing %v", err)
} }
msgs := make([]*Message, 0, 0) msgs := make([]*Message, 0, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
message := &Message{ message := &Message{
Header: map[string]string{ Header: map[string]string{
@ -74,7 +74,7 @@ func TestMemoryBroker(t *testing.T) {
t.Fatalf("Unexpected error subscribing %v", err) t.Fatalf("Unexpected error subscribing %v", err)
} }
msgs := make([]*Message, 0, 0) msgs := make([]*Message, 0, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
message := &Message{ message := &Message{
Header: map[string]string{ Header: map[string]string{

View File

@ -19,8 +19,8 @@ import (
// Options holds client options // Options holds client options
type Options struct { type Options struct {
// Router used to get route // Transport used for transfer messages
Router router.Router Transport transport.Transport
// Selector used to select needed address // Selector used to select needed address
Selector selector.Selector Selector selector.Selector
// Logger used to log messages // Logger used to log messages
@ -31,18 +31,16 @@ type Options struct {
Broker broker.Broker Broker broker.Broker
// Meter used for metrics // Meter used for metrics
Meter meter.Meter Meter meter.Meter
// Transport used for transfer messages
Transport transport.Transport
// Context is used for external options // Context is used for external options
Context context.Context 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
Codecs map[string]codec.Codec Codecs map[string]codec.Codec
// Lookup func used to get destination addr // Lookup func used to get destination addr
Lookup LookupFunc 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 is used for proxy requests
Proxy string Proxy string
// ContentType is used to select codec // ContentType is used to select codec
@ -51,6 +49,8 @@ type Options struct {
Name string Name string
// Wrappers contains wrappers // Wrappers contains wrappers
Wrappers []Wrapper Wrappers []Wrapper
// CallOptions contains default CallOptions
CallOptions CallOptions
// PoolSize connection pool size // PoolSize connection pool size
PoolSize int PoolSize int
// PoolTTL connection pool ttl // PoolTTL connection pool ttl
@ -68,12 +68,12 @@ func NewCallOptions(opts ...CallOption) CallOptions {
// CallOptions holds client call options // CallOptions holds client call options
type CallOptions struct { type CallOptions struct {
// Router used for route
Router router.Router
// Selector selects addr // Selector selects addr
Selector selector.Selector Selector selector.Selector
// Context used for deadline // Context used for deadline
Context context.Context Context context.Context
// Router used for route
Router router.Router
// Retry func used for retries // Retry func used for retries
Retry RetryFunc Retry RetryFunc
// Backoff func used for backoff when retry // Backoff func used for backoff when retry
@ -82,22 +82,22 @@ type CallOptions struct {
Network string Network string
// Content-Type // Content-Type
ContentType string ContentType string
// CallWrappers call wrappers // AuthToken string
CallWrappers []CallWrapper AuthToken string
// SelectOptions selector options
SelectOptions []selector.SelectOption
// Address specifies static addr list // Address specifies static addr list
Address []string Address []string
// Retries specifies retries num // SelectOptions selector options
Retries int SelectOptions []selector.SelectOption
// CallWrappers call wrappers
CallWrappers []CallWrapper
// StreamTimeout stream timeout // StreamTimeout stream timeout
StreamTimeout time.Duration StreamTimeout time.Duration
// RequestTimeout request timeout // RequestTimeout request timeout
RequestTimeout time.Duration RequestTimeout time.Duration
// DialTimeout dial timeout // DialTimeout dial timeout
DialTimeout time.Duration DialTimeout time.Duration
// AuthToken string // Retries specifies retries num
AuthToken string Retries int
} }
// Context pass context to client // Context pass context to client
@ -118,12 +118,12 @@ func NewPublishOptions(opts ...PublishOption) PublishOptions {
// PublishOptions holds publish options // PublishOptions holds publish options
type PublishOptions struct { type PublishOptions struct {
// BodyOnly will publish only message body
BodyOnly bool
// Context used for external options // Context used for external options
Context context.Context Context context.Context
// Exchange topic exchange name // Exchange topic exchange name
Exchange string Exchange string
// BodyOnly will publish only message body
BodyOnly bool
} }
// NewMessageOptions creates message options struct // NewMessageOptions creates message options struct

View File

@ -58,7 +58,7 @@ type Message struct {
Method string Method string
Endpoint string Endpoint string
Error string Error string
Id string ID string
Body []byte Body []byte
Type MessageType Type MessageType
} }

View File

@ -37,8 +37,8 @@ var (
// Error type // Error type
type Error struct { type Error struct {
// Id holds error id or service, usually someting like my_service or id // ID holds error id or service, usually someting like my_service or id
Id string ID string
// Detail holds some useful details about error // Detail holds some useful details about error
Detail string Detail string
// Status usually holds text of http status // Status usually holds text of http status
@ -56,7 +56,7 @@ func (e *Error) Error() string {
// New generates a custom error // New generates a custom error
func New(id, detail string, code int32) error { func New(id, detail string, code int32) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: code, Code: code,
Detail: detail, Detail: detail,
Status: http.StatusText(int(code)), Status: http.StatusText(int(code)),
@ -77,7 +77,7 @@ func Parse(err string) *Error {
// BadRequest generates a 400 error. // BadRequest generates a 400 error.
func BadRequest(id, format string, a ...interface{}) error { func BadRequest(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 400, Code: 400,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(400), Status: http.StatusText(400),
@ -87,7 +87,7 @@ func BadRequest(id, format string, a ...interface{}) error {
// Unauthorized generates a 401 error. // Unauthorized generates a 401 error.
func Unauthorized(id, format string, a ...interface{}) error { func Unauthorized(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 401, Code: 401,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(401), Status: http.StatusText(401),
@ -97,7 +97,7 @@ func Unauthorized(id, format string, a ...interface{}) error {
// Forbidden generates a 403 error. // Forbidden generates a 403 error.
func Forbidden(id, format string, a ...interface{}) error { func Forbidden(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 403, Code: 403,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(403), Status: http.StatusText(403),
@ -107,7 +107,7 @@ func Forbidden(id, format string, a ...interface{}) error {
// NotFound generates a 404 error. // NotFound generates a 404 error.
func NotFound(id, format string, a ...interface{}) error { func NotFound(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 404, Code: 404,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(404), Status: http.StatusText(404),
@ -117,7 +117,7 @@ func NotFound(id, format string, a ...interface{}) error {
// MethodNotAllowed generates a 405 error. // MethodNotAllowed generates a 405 error.
func MethodNotAllowed(id, format string, a ...interface{}) error { func MethodNotAllowed(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 405, Code: 405,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(405), Status: http.StatusText(405),
@ -127,7 +127,7 @@ func MethodNotAllowed(id, format string, a ...interface{}) error {
// Timeout generates a 408 error. // Timeout generates a 408 error.
func Timeout(id, format string, a ...interface{}) error { func Timeout(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 408, Code: 408,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(408), Status: http.StatusText(408),
@ -137,7 +137,7 @@ func Timeout(id, format string, a ...interface{}) error {
// Conflict generates a 409 error. // Conflict generates a 409 error.
func Conflict(id, format string, a ...interface{}) error { func Conflict(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 409, Code: 409,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(409), Status: http.StatusText(409),
@ -147,7 +147,7 @@ func Conflict(id, format string, a ...interface{}) error {
// InternalServerError generates a 500 error. // InternalServerError generates a 500 error.
func InternalServerError(id, format string, a ...interface{}) error { func InternalServerError(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 500, Code: 500,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(500), Status: http.StatusText(500),
@ -157,7 +157,7 @@ func InternalServerError(id, format string, a ...interface{}) error {
// NotImplemented generates a 501 error // NotImplemented generates a 501 error
func NotImplemented(id, format string, a ...interface{}) error { func NotImplemented(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 501, Code: 501,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(501), Status: http.StatusText(501),
@ -167,7 +167,7 @@ func NotImplemented(id, format string, a ...interface{}) error {
// BadGateway generates a 502 error // BadGateway generates a 502 error
func BadGateway(id, format string, a ...interface{}) error { func BadGateway(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 502, Code: 502,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(502), Status: http.StatusText(502),
@ -177,7 +177,7 @@ func BadGateway(id, format string, a ...interface{}) error {
// ServiceUnavailable generates a 503 error // ServiceUnavailable generates a 503 error
func ServiceUnavailable(id, format string, a ...interface{}) error { func ServiceUnavailable(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 503, Code: 503,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(503), Status: http.StatusText(503),
@ -187,7 +187,7 @@ func ServiceUnavailable(id, format string, a ...interface{}) error {
// GatewayTimeout generates a 504 error // GatewayTimeout generates a 504 error
func GatewayTimeout(id, format string, a ...interface{}) error { func GatewayTimeout(id, format string, a ...interface{}) error {
return &Error{ return &Error{
Id: id, ID: id,
Code: 504, Code: 504,
Detail: fmt.Sprintf(format, a...), Detail: fmt.Sprintf(format, a...),
Status: http.StatusText(504), Status: http.StatusText(504),

View File

@ -9,12 +9,12 @@ import (
func TestFromError(t *testing.T) { func TestFromError(t *testing.T) {
err := NotFound("go.micro.test", "%s", "example") err := NotFound("go.micro.test", "%s", "example")
merr := FromError(err) 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) t.Fatalf("invalid conversation %v != %v", err, merr)
} }
err = er.New(err.Error()) err = er.New(err.Error())
merr = FromError(err) 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) t.Fatalf("invalid conversation %v != %v", err, merr)
} }
} }
@ -36,7 +36,7 @@ func TestEqual(t *testing.T) {
func TestErrors(t *testing.T) { func TestErrors(t *testing.T) {
testData := []*Error{ testData := []*Error{
{ {
Id: "test", ID: "test",
Code: 500, Code: 500,
Detail: "Internal server error", Detail: "Internal server error",
Status: http.StatusText(500), Status: http.StatusText(500),
@ -44,7 +44,7 @@ func TestErrors(t *testing.T) {
} }
for _, e := range testData { 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() { if e.Error() != ne.Error() {
t.Fatalf("Expected %s got %s", 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) t.Fatalf("Expected error got nil %v", pe)
} }
if pe.Id != e.Id { if pe.ID != e.ID {
t.Fatalf("Expected %s got %s", e.Id, pe.Id) t.Fatalf("Expected %s got %s", e.ID, pe.ID)
} }
if pe.Detail != e.Detail { if pe.Detail != e.Detail {

View File

@ -426,9 +426,9 @@ func (f *microFlow) WorkflowLoad(ctx context.Context, id string) (Workflow, erro
type microCallStep struct { type microCallStep struct {
rsp *Message rsp *Message
req *Message req *Message
opts StepOptions
service string service string
method string method string
opts StepOptions
status Status status Status
} }
@ -510,8 +510,8 @@ func (s *microCallStep) Execute(ctx context.Context, req *Message, opts ...Execu
type microPublishStep struct { type microPublishStep struct {
req *Message req *Message
rsp *Message rsp *Message
opts StepOptions
topic string topic string
opts StepOptions
status Status status Status
} }

View File

@ -96,8 +96,8 @@ type WorkflowOption func(*WorkflowOptions)
// WorkflowOptions holds workflow options // WorkflowOptions holds workflow options
type WorkflowOptions struct { type WorkflowOptions struct {
ID string
Context context.Context Context context.Context
ID string
} }
// WorkflowID set workflow id // WorkflowID set workflow id
@ -193,10 +193,10 @@ func NewExecuteOptions(opts ...ExecuteOption) ExecuteOptions {
} }
type StepOptions struct { type StepOptions struct {
ID string
Context context.Context Context context.Context
Requires []string
Fallback string Fallback string
ID string
Requires []string
} }
type StepOption func(*StepOptions) type StepOption func(*StepOptions)

View File

@ -27,8 +27,8 @@ type Options struct {
Tracer tracer.Tracer Tracer tracer.Tracer
// Tunnel used for transfer data // Tunnel used for transfer data
Tunnel tunnel.Tunnel Tunnel tunnel.Tunnel
// Id of the node // ID of the node
Id string ID string
// Name of the network // Name of the network
Name string Name string
// Address to bind to // Address to bind to
@ -39,10 +39,10 @@ type Options struct {
Nodes []string Nodes []string
} }
// Id sets the id of the network node // ID sets the id of the network node
func Id(id string) Option { func ID(id string) Option {
return func(o *Options) { 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 // NewOptions returns network default options
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Id: id.Must(), ID: id.Must(),
Name: "go.micro", Name: "go.micro",
Address: ":0", Address: ":0",
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,

View File

@ -38,8 +38,8 @@ func (t EventType) String() string {
type Event struct { type Event struct {
// Timestamp is event timestamp // Timestamp is event timestamp
Timestamp time.Time Timestamp time.Time
// Id of the event // ID of the event
Id string ID string
// Route is table route // Route is table route
Route Route Route Route
// Type defines type of event // Type defines type of event

View File

@ -13,7 +13,7 @@ func TestError(t *testing.T) {
if !ok { if !ok {
t.Fatal("error not *errors.Error") t.Fatal("error not *errors.Error")
} }
if merr.Id != "svc1" { if merr.ID != "svc1" {
t.Fatal("id != svc1") t.Fatal("id != svc1")
} }
} }

View File

@ -51,7 +51,7 @@ func (m *memorySync) Leader(id string, opts ...LeaderOption) (Leader, error) {
id: id, id: id,
resign: func(id string) error { resign: func(id string) error {
once.Do(func() { once.Do(func() {
m.Unlock(id) _ = m.Unlock(id)
}) })
return nil return nil
}, },

View File

@ -16,7 +16,7 @@ import (
var ( var (
// ErrInvalidParam is returned when invalid data is provided to the ToJSON or Unmarshal function. // 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. // 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 bracketSplitter *regexp.Regexp
) )

View File

@ -29,6 +29,7 @@ func Stores(stores ...store.Store) Option {
} }
} }
// nolint: golint,revive
// SyncInterval sets the duration between syncs from L0 to L1 // SyncInterval sets the duration between syncs from L0 to L1
func SyncInterval(d time.Duration) Option { func SyncInterval(d time.Duration) Option {
return func(o *Options) { 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 // SyncMultiplier sets the multiplication factor for time to wait each sync layer
func SyncMultiplier(i int64) Option { func SyncMultiplier(i int64) Option {
return func(o *Options) { return func(o *Options) {