Skip to content

Commit d633bfd

Browse files
authored
refactor: use slices.Contains to simplify code (#698)
Signed-off-by: joemicky <joemickychang@outlook.com>
1 parent c0b52ff commit d633bfd

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

cmd/hash/hash.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"hash"
99
"io"
1010
"os"
11+
"slices"
1112
"strings"
1213

1314
"github.com/spf13/cobra"
@@ -85,10 +86,8 @@ var HashCmd = &cobra.Command{
8586
if len(args) < 1 {
8687
return fmt.Errorf("expected 1 argument to specify hash function. got %d", len(args))
8788
}
88-
for _, v := range supportedHashFunctions {
89-
if v == args[0] {
90-
return nil
91-
}
89+
if slices.Contains(supportedHashFunctions, args[0]) {
90+
return nil
9291
}
9392

9493
return fmt.Errorf("the name %s is not recognized. Please use one of the following: %s", args[0], strings.Join(supportedHashFunctions, ","))

cmd/loadtest/loadtest.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"math/rand"
1414
"net/http"
1515
"net/url"
16+
"slices"
1617

1718
"os"
1819
"os/signal"
@@ -132,20 +133,10 @@ func modeRequiresLoadTestContract(m loadTestMode) bool {
132133
return false
133134
}
134135
func anyModeRequiresLoadTestContract(modes []loadTestMode) bool {
135-
for _, m := range modes {
136-
if modeRequiresLoadTestContract(m) {
137-
return true
138-
}
139-
}
140-
return false
136+
return slices.ContainsFunc(modes, modeRequiresLoadTestContract)
141137
}
142138
func hasMode(mode loadTestMode, modes []loadTestMode) bool {
143-
for _, m := range modes {
144-
if m == mode {
145-
return true
146-
}
147-
}
148-
return false
139+
return slices.Contains(modes, mode)
149140
}
150141

151142
func hasUniqueModes(modes []loadTestMode) bool {

0 commit comments

Comments
 (0)