diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-11-18 17:31:20 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-11-18 17:31:20 +0300 |
commit | ed5be5c6020dedda33dc43b99fa768e654c6e674 (patch) | |
tree | bd92ea1d0dae55c20580be8a143f63fc4d6b8cc5 | |
parent | 7ccf260198eb4abb9b16e8c82ac1db605113640d (diff) |
refactor: use multierror in config validation
-rw-r--r-- | internal/config/validate.go | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/internal/config/validate.go b/internal/config/validate.go index 32238786..1e6edca0 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -22,19 +22,16 @@ var ( // Validate values populated in Config func Validate(config *Config) error { - if err := validateListeners(config); err != nil { - return err - } - - if err := validateAuthConfig(config); err != nil { - return err - } + var result *multierror.Error - if err := validateArtifactsServerConfig(config); err != nil { - return err - } + result = multierror.Append(result, + validateListeners(config), + validateAuthConfig(config), + validateArtifactsServerConfig(config), + tls.ValidateTLSVersions(*tlsMinVersion, *tlsMaxVersion), + ) - return tls.ValidateTLSVersions(*tlsMinVersion, *tlsMaxVersion) + return result.ErrorOrNil() } func validateListeners(config *Config) error { @@ -82,14 +79,17 @@ func validateArtifactsServerConfig(config *Config) error { if err != nil { return err } + + var result *multierror.Error + // url.Parse ensures that the Scheme attribute is always lower case. if u.Scheme != "http" && u.Scheme != "https" { - return ErrArtifactsServerUnsupportedScheme + result = multierror.Append(result, ErrArtifactsServerUnsupportedScheme) } if config.ArtifactsServer.TimeoutSeconds < 1 { - return ErrArtifactsServerInvalidTimeout + result = multierror.Append(result, ErrArtifactsServerInvalidTimeout) } - return nil + return result.ErrorOrNil() } |