Skip to content

Commit

Permalink
cleanup: use slices package
Browse files Browse the repository at this point in the history
This commit replaces the user implemented function
`CheckSliceContains()` with `slices.Contains()`
function introduced in Go 1.21.

Signed-off-by: Praveen M <m.praveen@ibm.com>
  • Loading branch information
iPraveenParihar authored and mergify[bot] committed Apr 5, 2024
1 parent 86a89d5 commit c146724
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
3 changes: 2 additions & 1 deletion internal/rbd/rbd_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -363,7 +364,7 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, c
}

func appendNbdDeviceTypeAndOptions(cmdArgs []string, userOptions, cookie string) []string {
isUnmap := util.CheckSliceContains(cmdArgs, "unmap")
isUnmap := slices.Contains(cmdArgs, "unmap")
if !isUnmap {
if !strings.Contains(userOptions, useNbdNetlink) {
cmdArgs = append(cmdArgs, "--"+useNbdNetlink)
Expand Down
13 changes: 1 addition & 12 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,6 @@ func CallStack() string {
return string(stack)
}

// CheckSliceContains checks the slice for string.
func CheckSliceContains(options []string, opt string) bool {
for _, o := range options {
if o == opt {
return true
}
}

return false
}

// GetVolumeContext filters out parameters that are not required in volume context.
func GetVolumeContext(parameters map[string]string) map[string]string {
volumeContext := map[string]string{}
Expand All @@ -403,7 +392,7 @@ func GetVolumeContext(parameters map[string]string) map[string]string {
topologyPoolsParam,
}
for k, v := range parameters {
if !CheckSliceContains(notRequiredParams, k) {
if !slices.Contains(notRequiredParams, k) {
volumeContext[k] = v
}
}
Expand Down

0 comments on commit c146724

Please sign in to comment.