moleculer-go/moleculer

View on GitHub

Showing 77 of 77 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func chainStarted(service moleculer.ServiceSchema, mixin *moleculer.Mixin) moleculer.ServiceSchema {
    if mixin.Started != nil {
        svcHook := service.Started
        mixinHook := mixin.Started
        service.Started = func(ctx moleculer.BrokerContext, svc moleculer.ServiceSchema) {
Severity: Major
Found in service/service.go and 1 other location - About 1 hr to fix
service/service.go on lines 280..292

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 144.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func chainStopped(service moleculer.ServiceSchema, mixin *moleculer.Mixin) moleculer.ServiceSchema {
    if mixin.Stopped != nil {
        svcHook := service.Stopped
        mixinHook := mixin.Stopped
        service.Stopped = func(ctx moleculer.BrokerContext, svc moleculer.ServiceSchema) {
Severity: Major
Found in service/service.go and 1 other location - About 1 hr to fix
service/service.go on lines 262..274

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 144.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 6 locations. Consider refactoring.
Open

    mapTransformer{
        "map[string]string",
        func(source *interface{}) map[string]interface{} {
            result := make(map[string]interface{}, len((*source).(map[string]string)))
            for key, value := range (*source).(map[string]string) {
Severity: Major
Found in payload/mapTransformers.go and 5 other locations - About 1 hr to fix
payload/mapTransformers.go on lines 47..59
payload/mapTransformers.go on lines 60..72
payload/mapTransformers.go on lines 73..85
payload/mapTransformers.go on lines 86..98
payload/mapTransformers.go on lines 99..111

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 144.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 6 locations. Consider refactoring.
Open

    mapTransformer{
        "map[string]float64",
        func(source *interface{}) map[string]interface{} {
            result := make(map[string]interface{}, len((*source).(map[string]float64)))
            for key, value := range (*source).(map[string]float64) {
Severity: Major
Found in payload/mapTransformers.go and 5 other locations - About 1 hr to fix
payload/mapTransformers.go on lines 34..46
payload/mapTransformers.go on lines 47..59
payload/mapTransformers.go on lines 60..72
payload/mapTransformers.go on lines 73..85
payload/mapTransformers.go on lines 86..98

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 144.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 6 locations. Consider refactoring.
Open

    mapTransformer{
        "map[string]int64",
        func(source *interface{}) map[string]interface{} {
            result := make(map[string]interface{}, len((*source).(map[string]int64)))
            for key, value := range (*source).(map[string]int64) {
Severity: Major
Found in payload/mapTransformers.go and 5 other locations - About 1 hr to fix
payload/mapTransformers.go on lines 34..46
payload/mapTransformers.go on lines 47..59
payload/mapTransformers.go on lines 73..85
payload/mapTransformers.go on lines 86..98
payload/mapTransformers.go on lines 99..111

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 144.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 6 locations. Consider refactoring.
Open

    mapTransformer{
        "map[string]uint64",
        func(source *interface{}) map[string]interface{} {
            result := make(map[string]interface{}, len((*source).(map[string]uint64)))
            for key, value := range (*source).(map[string]uint64) {
Severity: Major
Found in payload/mapTransformers.go and 5 other locations - About 1 hr to fix
payload/mapTransformers.go on lines 34..46
payload/mapTransformers.go on lines 47..59
payload/mapTransformers.go on lines 60..72
payload/mapTransformers.go on lines 86..98
payload/mapTransformers.go on lines 99..111

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 144.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (broker *ServiceBroker) Emit(event string, params interface{}, groups ...string) {
    broker.logger.Trace("Broker - Emit() event: ", event, " params: ", params, " groups: ", groups)
    if !broker.IsStarted() {
        panic(errors.New("Broker must be started before emiting events :("))
    }
Severity: Major
Found in broker/broker.go and 1 other location - About 1 hr to fix
broker/broker.go on lines 561..568

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 132.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (broker *ServiceBroker) Broadcast(event string, params interface{}, groups ...string) {
    broker.logger.Trace("Broker - Broadcast() event: ", event, " params: ", params, " groups: ", groups)
    if !broker.IsStarted() {
        panic(errors.New("Broker must be started before broadcasting events :("))
    }
Severity: Major
Found in broker/broker.go and 1 other location - About 1 hr to fix
broker/broker.go on lines 552..559

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 132.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if item.Kind() == reflect.Map {
            mt := MapTransformer(&value)
            result[key] = mt.AsMap(&value)
        } else if item.Kind() == reflect.Array || item.Kind() == reflect.Slice {
            at := ArrayTransformer(&value)
Severity: Major
Found in payload/mapTransformers.go and 1 other location - About 1 hr to fix
payload/arrayTransformers.go on lines 236..244

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 131.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if item.Kind() == reflect.Map {
            mt := MapTransformer(&value)
            result[i] = mt.AsMap(&value)
        } else if item.Kind() == reflect.Array || item.Kind() == reflect.Slice {
            at := ArrayTransformer(&value)
Severity: Major
Found in payload/arrayTransformers.go and 1 other location - About 1 hr to fix
payload/mapTransformers.go on lines 159..167

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 131.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Avoid deeply nested control flow statements.
Open

    } else if strings.ToUpper(broker.config.LogLevel) == "FATAL" {
        log.SetLevel(log.FatalLevel)
    } else {
        log.SetLevel(log.InfoLevel)
    }
Severity: Major
Found in broker/broker.go - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                    if selected := stg.Select(nodes); selected != nil {
                        entry := (*selected).(*EventEntry)
                        result = append(result, entry)
                    }
    Severity: Major
    Found in registry/eventCatalog.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

          } else if isKafka(pubsub.broker.Config.Transporter) {
              pubsub.logger.Info("Transporter: KafkaTransporter")
              transport = pubsub.createKafkaTransporter()
          } else {
              pubsub.logger.Info("Transporter: Memory")
      Severity: Major
      Found in transit/pubsub/pubsub.go - About 45 mins to fix

        Method TCPTransporter.onGossipResponse has 7 return statements (exceeds 4 allowed).
        Open

        func (transporter *TCPTransporter) onGossipResponse(msgBytes *[]byte) {
            payload := transporter.serializer.BytesToPayload(msgBytes)
            sender := payload.Get("sender").String()
        
            transporter.logger.Trace("Received gossip response from " + sender)
        Severity: Major
        Found in transit/tcp/gossip.go - About 45 mins to fix

          Method RawPayload.Get has 7 return statements (exceeds 4 allowed).
          Open

          func (p *RawPayload) Get(s string, defaultValue ...interface{}) moleculer.Payload {
              if _, ok := p.mapGet(s); ok {
                  if defaultValue != nil {
                      return p.getKey(s, defaultValue...)
                  }
          Severity: Major
          Found in payload/payload.go - About 45 mins to fix

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            var mathService = moleculer.ServiceSchema{
                Name: "math",
                Actions: []moleculer.Action{
                    {
                        Name: "add",
            Severity: Minor
            Found in examples/amqp_transporter/main.go and 1 other location - About 45 mins to fix
            examples/standalone/math.service.go on lines 11..21

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 114.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            var mathService = moleculer.ServiceSchema{
                Name: "math",
                Actions: []moleculer.Action{
                    {
                        Name: "add",
            Severity: Minor
            Found in examples/standalone/math.service.go and 1 other location - About 45 mins to fix
            examples/amqp_transporter/main.go on lines 17..27

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 114.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Method TCPTransporter.Publish has 6 return statements (exceeds 4 allowed).
            Open

            func (transporter *TCPTransporter) Publish(command, nodeID string, message moleculer.Payload) {
                transporter.logger.Debug("TCPTransporter.Publish() command: " + command + " to nodeID: " + nodeID)
                if command == "DISCOVER" {
                    if transporter.udpServer != nil {
                        transporter.udpServer.BroadcastDiscoveryMessage()
            Severity: Major
            Found in transit/tcp/tcp-transporter.go - About 40 mins to fix

              Method TCPTransporter.onGossipRequest has 6 return statements (exceeds 4 allowed).
              Open

              func (transporter *TCPTransporter) onGossipRequest(msgBytes *[]byte) {
                  payload := transporter.serializer.BytesToPayload(msgBytes)
                  sender := payload.Get("sender").String()
              
                  transporter.logger.Trace("Received gossip request from " + sender)
              Severity: Major
              Found in transit/tcp/gossip.go - About 40 mins to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func (actionCatalog *ActionCatalog) listByName() map[string][]ActionEntry {
                    result := make(map[string][]ActionEntry)
                    actionCatalog.actions.Range(func(key, value interface{}) bool {
                        result[key.(string)] = value.([]ActionEntry)
                        return true
                Severity: Minor
                Found in registry/actionCatalog.go and 1 other location - About 40 mins to fix
                registry/eventCatalog.go on lines 79..86

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 109.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Severity
                Category
                Status
                Source
                Language