Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
sinadarbouy committed Jul 14, 2024
1 parent e49a7c3 commit 04334b8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
11 changes: 8 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Check failure on line 879 in cmd/run.go

View workflow job for this annotation

GitHub Actions / Test GatewayD

line is 142 characters (lll)
logger.Error().Str("proxyName", proxyName).Msg("failed to find proxy configuration")
return
}
serverProxies = append(serverProxies, proxy)
}

servers[name] = network.NewServer(
Expand Down
2 changes: 1 addition & 1 deletion config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
ErrCodeMsgEncodeError
ErrCodeConfigParseError
ErrCodePublishAsyncAction
ErrorCodeErrLoadbalancerStrategyNotFound
ErrorCodeLoadBalancerStrategyNotFound
)

var (
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions gatewayd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions network/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

0 comments on commit 04334b8

Please sign in to comment.