diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-31 20:30:17 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-02-01 03:02:44 +0300 |
commit | 066ac20ffe98a7cf3e3d35e3a489459dec12f157 (patch) | |
tree | 8d91ba4f0a9e99a94f83e27e8a75d4697e028e48 /internal/config | |
parent | 17779736478d44af08782dec0e7c892c31b71297 (diff) |
lint: reduce cyclomatic complexity of validateListeners func
Diffstat (limited to 'internal/config')
-rw-r--r-- | internal/config/validate.go | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/internal/config/validate.go b/internal/config/validate.go index 1b5775af..a3dbcc3b 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -45,24 +45,22 @@ func validateListeners(config *Config) error { } var result *multierror.Error - for i, s := range config.ListenHTTPStrings.Split() { - if s == "" { - result = multierror.Append(result, fmt.Errorf("empty http listener at index %d: %w", i, errEmptyListener)) - } - } - for i, s := range config.ListenHTTPSStrings.Split() { - if s == "" { - result = multierror.Append(result, fmt.Errorf("empty https listener at index %d: %w", i, errEmptyListener)) - } - } - for i, s := range config.ListenHTTPSProxyv2Strings.Split() { - if s == "" { - result = multierror.Append(result, fmt.Errorf("empty proxyv2 listener at index %d: %w", i, errEmptyListener)) - } - } - for i, s := range config.ListenProxyStrings.Split() { + + result = multierror.Append(result, + validateListenerAddr(config.ListenHTTPStrings, "http"), + validateListenerAddr(config.ListenHTTPSStrings, "https"), + validateListenerAddr(config.ListenHTTPSProxyv2Strings, "proxyv2"), + validateListenerAddr(config.ListenProxyStrings, "proxy"), + ) + + return result.ErrorOrNil() +} + +func validateListenerAddr(listeners MultiStringFlag, name string) error { + var result *multierror.Error + for i, s := range listeners.Split() { if s == "" { - result = multierror.Append(result, fmt.Errorf("empty proxy listener at index %d: %w", i, errEmptyListener)) + result = multierror.Append(result, fmt.Errorf("empty %s listener at index %d: %w", name, i, errEmptyListener)) } } |