Skip to content

Commit

Permalink
Merge pull request #2875 from dashangcun/master
Browse files Browse the repository at this point in the history
refactor: using slices.Contains to simplify the code
  • Loading branch information
eljobe authored Jan 15, 2025
2 parents d896e9c + 1304d5f commit 9d65a2f
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions cmd/conf/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package conf
import (
"fmt"
"runtime"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -106,7 +107,7 @@ func (c *InitConfig) Validate() error {
if c.Force && c.RecreateMissingStateFrom > 0 {
log.Warn("force init enabled, recreate-missing-state-from will have no effect")
}
if c.Latest != "" && !isAcceptedSnapshotKind(c.Latest) {
if c.Latest != "" && !slices.Contains(acceptedSnapshotKinds, c.Latest) {
return fmt.Errorf("invalid value for latest option: \"%s\" %s", c.Latest, acceptedSnapshotKindsStr)
}
if c.Prune != "" && c.PruneThreads <= 0 {
Expand Down Expand Up @@ -139,12 +140,3 @@ var (
acceptedSnapshotKinds = []string{"archive", "pruned", "genesis"}
acceptedSnapshotKindsStr = "(accepted values: \"" + strings.Join(acceptedSnapshotKinds, "\" | \"") + "\")"
)

func isAcceptedSnapshotKind(kind string) bool {
for _, valid := range acceptedSnapshotKinds {
if kind == valid {
return true
}
}
return false
}

0 comments on commit 9d65a2f

Please sign in to comment.