Showing 24 of 65 total issues
Function createNodeService
has a Cognitive Complexity of 127 (exceeds 20 allowed). Consider refactoring. Open
func createNodeService(registry *ServiceRegistry) *service.Service {
var startedTime time.Time
isAvailable := func(nodeID string) bool {
node, exists := registry.nodes.findNode(nodeID)
return exists && node.IsAvailable()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File service.go
has 845 lines of code (exceeds 500 allowed). Consider refactoring. Open
package service
import (
"errors"
"fmt"
Function createNodeService
has 249 lines of code (exceeds 50 allowed). Consider refactoring. Open
func createNodeService(registry *ServiceRegistry) *service.Service {
var startedTime time.Time
isAvailable := func(nodeID string) bool {
node, exists := registry.nodes.findNode(nodeID)
return exists && node.IsAvailable()
RawPayload
has 46 methods (exceeds 20 allowed). Consider refactoring. Open
type RawPayload struct {
source interface{}
}
JSONPayload
has 44 methods (exceeds 20 allowed). Consider refactoring. Open
type JSONPayload struct {
result gjson.Result
logger *log.Entry
}
PubSub
has 41 methods (exceeds 20 allowed). Consider refactoring. Open
type PubSub struct {
logger *log.Entry
transport transit.Transport
broker *moleculer.BrokerDelegates
isConnected bool
Function mergeConfigs
has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring. Open
func mergeConfigs(baseConfig moleculer.Config, userConfig []*moleculer.Config) moleculer.Config {
if len(userConfig) > 0 {
for _, config := range userConfig {
if config.Services != nil {
baseConfig.Services = mergeMaps(baseConfig.Services, config.Services)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File pubsub.go
has 612 lines of code (exceeds 500 allowed). Consider refactoring. Open
package pubsub
import (
"errors"
"fmt"
ServiceBroker
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
type ServiceBroker struct {
namespace string
logger *log.Entry
File payload.go
has 574 lines of code (exceeds 500 allowed). Consider refactoring. Open
package payload
import (
"errors"
"fmt"
ServiceRegistry
has 30 methods (exceeds 20 allowed). Consider refactoring. Open
type ServiceRegistry struct {
logger *log.Entry
transit transit.Transit
localNode moleculer.Node
nodes *NodeCatalog
File jsonSerializer.go
has 563 lines of code (exceeds 500 allowed). Consider refactoring. Open
package serializer
import (
"bytes"
"encoding/json"
Context
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
type Context struct {
id string
requestID string
broker *moleculer.BrokerDelegates
targetNodeID string
File broker.go
has 518 lines of code (exceeds 500 allowed). Consider refactoring. Open
package broker
import (
"errors"
"strings"
Service
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
type Service struct {
nodeID string
fullname string
name string
version string
Method EventCatalog.Find
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
func (eventCatalog *EventCatalog) Find(name string, groups []string, preferLocal bool, localOnly bool, stg strategy.Strategy) []*EventEntry {
events, exists := eventCatalog.events.Load(name)
if !exists {
return make([]*EventEntry, 0)
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method ServiceRegistry.remoteNodeInfoReceived
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (registry *ServiceRegistry) remoteNodeInfoReceived(message moleculer.Payload) {
registry.nodeReceivedMutex.Lock()
defer registry.nodeReceivedMutex.Unlock()
nodeID := message.Get("sender").String()
services := message.Get("services").MapArray()
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...)
}
Avoid deeply nested control flow statements. Open
if selected := stg.Select(nodes); selected != nil {
entry := (*selected).(*EventEntry)
result = append(result, entry)
}
Avoid deeply nested control flow statements. Open
} else if strings.ToUpper(broker.config.LogLevel) == "FATAL" {
log.SetLevel(log.FatalLevel)
} else {
log.SetLevel(log.InfoLevel)
}