From 04334b879afa0acce6838f9479b65353b591b5cf Mon Sep 17 00:00:00 2001 From: sinadarbouy Date: Sun, 14 Jul 2024 18:42:39 +0200 Subject: [PATCH] clean code --- cmd/run.go | 11 ++++++++--- config/constants.go | 2 +- errors/errors.go | 6 +++--- gatewayd.yaml | 12 +++++++----- network/loadbalancer.go | 4 +--- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index c13d8334..bb6ce605 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -873,9 +873,14 @@ var runCmd = &cobra.Command{ logger := loggers[name] var serverProxies []network.IProxy - - for _, proxy_name := range cfg.Proxies { - serverProxies = append(serverProxies, proxies[proxy_name]) + for _, proxyName := range cfg.Proxies { + proxy, exists := proxies[proxyName] + if !exists { + // Error: Proxy configuration not found for 'proxyName'. This may occur if a proxy referenced in the server configuration does not exist. + logger.Error().Str("proxyName", proxyName).Msg("failed to find proxy configuration") + return + } + serverProxies = append(serverProxies, proxy) } servers[name] = network.NewServer( diff --git a/config/constants.go b/config/constants.go index 763a7571..83d9dca4 100644 --- a/config/constants.go +++ b/config/constants.go @@ -93,7 +93,7 @@ const ( DefaultListenAddress = "0.0.0.0:15432" DefaultTickInterval = 5 * time.Second DefaultHandshakeTimeout = 5 * time.Second - DefaultLoadBalancerStrategy = "round-robin" + DefaultLoadBalancerStrategy = "ROUND_ROBIN" // Utility constants. DefaultSeed = 1000 diff --git a/errors/errors.go b/errors/errors.go index 74099aee..31a9b887 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -53,7 +53,7 @@ const ( ErrCodeMsgEncodeError ErrCodeConfigParseError ErrCodePublishAsyncAction - ErrorCodeErrLoadbalancerStrategyNotFound + ErrorCodeLoadBalancerStrategyNotFound ) var ( @@ -195,8 +195,8 @@ var ( ErrCodePublishAsyncAction, "error publishing async action", nil, } - ErrLoadbalancerStrategyNotFound = &GatewayDError{ - ErrorCodeErrLoadbalancerStrategyNotFound, "given strategy does not exists!", nil, + ErrLoadBalancerStrategyNotFound = &GatewayDError{ + ErrorCodeLoadBalancerStrategyNotFound, "The specified load balancer strategy does not exist.", nil, } // Unwrapped errors. diff --git a/gatewayd.yaml b/gatewayd.yaml index e05ce2c6..90fa2d73 100644 --- a/gatewayd.yaml +++ b/gatewayd.yaml @@ -3,7 +3,7 @@ loggers: default: output: ["console"] # "stdout", "stderr", "syslog", "rsyslog" and "file" - level: "info" # panic, fatal, error, warn, info (default), debug, trace + level: "debug" # panic, fatal, error, warn, info (default), debug, trace noColor: False timeFormat: "unix" # unixms, unixmicro and unixnano consoleTimeFormat: "RFC3339" # Go time format string @@ -46,7 +46,7 @@ clients: backoff: 1s # duration backoffMultiplier: 2.0 # 0 means no backoff disableBackoffCaps: false - read-db-2: + read-db: network: tcp address: localhost:5433 tcpKeepAlive: False @@ -65,20 +65,22 @@ clients: pools: default: size: 10 - read-db-2: + read-db: size: 10 proxies: default: healthCheckPeriod: 60s # duration - read-db-2: + read-db: healthCheckPeriod: 60s # duration servers: default: network: tcp address: 0.0.0.0:15432 - proxies: ["default","read-db-2"] + proxies: + - "default" + - "read-db" loadBalancer: strategy: ROUND_ROBIN enableTicker: False diff --git a/network/loadbalancer.go b/network/loadbalancer.go index d80a6e96..54ce84c5 100644 --- a/network/loadbalancer.go +++ b/network/loadbalancer.go @@ -17,8 +17,6 @@ func NewLoadBalancerStrategy(server *Server) (LoadBalancerStrategy, *gerr.Gatewa case "ROUND_ROBIN": return NewRoundRobin(server), nil default: - return nil, gerr.ErrLoadbalancerStrategyNotFound - + return nil, gerr.ErrLoadBalancerStrategyNotFound } - }