Use generic Contains rather than deprecated ContainsString
Kubernetes-commit: 8312c3ec242faf30f3967e59465ca5a764a4ee85
This commit is contained in:
parent
608a0553d7
commit
61dc2ecb38
|
@ -317,7 +317,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||
switch typedValue := value.(type) {
|
||||
case map[string]interface{}:
|
||||
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
||||
if slice.ContainsString(skip, skipExpr, nil) {
|
||||
if slice.Contains[string](skip, skipExpr, nil) {
|
||||
continue
|
||||
}
|
||||
w.Write(level, "%s:\n", smartLabelFor(field))
|
||||
|
@ -325,7 +325,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||
|
||||
case []interface{}:
|
||||
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
||||
if slice.ContainsString(skip, skipExpr, nil) {
|
||||
if slice.Contains[string](skip, skipExpr, nil) {
|
||||
continue
|
||||
}
|
||||
w.Write(level, "%s:\n", smartLabelFor(field))
|
||||
|
@ -340,7 +340,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||
|
||||
default:
|
||||
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
||||
if slice.ContainsString(skip, skipExpr, nil) {
|
||||
if slice.Contains[string](skip, skipExpr, nil) {
|
||||
continue
|
||||
}
|
||||
w.Write(level, "%s:\t%v\n", smartLabelFor(field), typedValue)
|
||||
|
@ -365,7 +365,7 @@ func smartLabelFor(field string) string {
|
|||
continue
|
||||
}
|
||||
|
||||
if slice.ContainsString(commonAcronyms, strings.ToUpper(part), nil) {
|
||||
if slice.Contains[string](commonAcronyms, strings.ToUpper(part), nil) {
|
||||
part = strings.ToUpper(part)
|
||||
} else {
|
||||
part = strings.Title(part)
|
||||
|
|
|
@ -23,8 +23,23 @@ import (
|
|||
// SortInts64 sorts []int64 in increasing order
|
||||
func SortInts64(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
|
||||
|
||||
// Contains checks if a given slice of type T contains the provided item.
|
||||
// If a modifier func is provided, it is called with the slice item before the comparation.
|
||||
func Contains[T comparable](slice []T, s T, modifier func(s T) T) bool {
|
||||
for _, item := range slice {
|
||||
if item == s {
|
||||
return true
|
||||
}
|
||||
if modifier != nil && modifier(item) == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ContainsString checks if a given slice of strings contains the provided string.
|
||||
// If a modifier func is provided, it is called with the slice item before the comparation.
|
||||
// Deprecated: Use Contains[T] instead
|
||||
func ContainsString(slice []string, s string, modifier func(s string) string) bool {
|
||||
for _, item := range slice {
|
||||
if item == s {
|
||||
|
|
Loading…
Reference in New Issue