diff --git a/cmd/util/cmd.go b/cmd/util/cmd.go index 16cc22f1a9..ec72cfceac 100644 --- a/cmd/util/cmd.go +++ b/cmd/util/cmd.go @@ -18,6 +18,7 @@ package cmdutil import ( "fmt" + "slices" "strings" ) @@ -49,12 +50,10 @@ func (c *CobraStringValue) IsSet() bool { return c.isSet } // Set sets a value and fails if it is not allowed func (c *CobraStringValue) Set(other string) error { - for _, s := range c.allowed { - if other == s { - c.value = other - c.isSet = true - return nil - } + if slices.Contains(c.allowed, other) { + c.value = other + c.isSet = true + return nil } return fmt.Errorf("value %s not allowed", other) } diff --git a/network/phonebook/phonebook_test.go b/network/phonebook/phonebook_test.go index b0805582d0..b07b8f2f7d 100644 --- a/network/phonebook/phonebook_test.go +++ b/network/phonebook/phonebook_test.go @@ -17,6 +17,7 @@ package phonebook import ( + "slices" "testing" "time" @@ -27,25 +28,13 @@ import ( func testPhonebookAll(t *testing.T, set []string, ph Phonebook) { actual := ph.GetAddresses(len(set), RelayRole) for _, got := range actual { - ok := false - for _, known := range set { - if got == known { - ok = true - break - } - } + ok := slices.Contains(set, got) if !ok { t.Errorf("get returned junk %#v", got) } } for _, known := range set { - ok := false - for _, got := range actual { - if got == known { - ok = true - break - } - } + ok := slices.Contains(actual, known) if !ok { t.Errorf("get missed %#v; actual=%#v; set=%#v", known, actual, set) }