Skip to content

Commit

Permalink
chore(settings): checkProviderNames uses provider.Parse
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed May 25, 2023
1 parent 771220d commit 7e4a2a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
4 changes: 0 additions & 4 deletions internal/config/settings/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ func andStrings(strings []string) (result string) {
return joinStrings(strings, "and")
}

func orStrings(strings []string) (result string) {
return joinStrings(strings, "or")
}

func joinStrings(strings []string, lastJoin string) (result string) {
if len(strings) == 0 {
return ""
Expand Down
19 changes: 3 additions & 16 deletions internal/config/settings/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,10 @@ func checkListeningAddress(address string) (err error) {
}

func checkProviderNames(providerNames []string) (err error) {
allProviders := provider.All()
allProviderNames := make([]string, len(allProviders))
for i, provider := range allProviders {
allProviderNames[i] = provider.Name
}

for _, providerName := range providerNames {
valid := false
for _, acceptedProviderName := range allProviderNames {
if strings.EqualFold(providerName, acceptedProviderName) {
valid = true
break
}
}
if !valid {
return fmt.Errorf("%w: %q must be one of: %s",
ErrValueNotOneOf, providerName, orStrings(allProviderNames))
_, err := provider.Parse(providerName)
if err != nil {
return fmt.Errorf("parsing provider: %w", err)
}
}

Expand Down

0 comments on commit 7e4a2a2

Please sign in to comment.