mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 04:52:08 +00:00
Use generic Contains rather than deprecated ContainsString
This commit is contained in:
parent
c3f15fd707
commit
8312c3ec24
@ -317,7 +317,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||||||
switch typedValue := value.(type) {
|
switch typedValue := value.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
||||||
if slice.ContainsString(skip, skipExpr, nil) {
|
if slice.Contains[string](skip, skipExpr, nil) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w.Write(level, "%s:\n", smartLabelFor(field))
|
w.Write(level, "%s:\n", smartLabelFor(field))
|
||||||
@ -325,7 +325,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||||||
|
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
||||||
if slice.ContainsString(skip, skipExpr, nil) {
|
if slice.Contains[string](skip, skipExpr, nil) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w.Write(level, "%s:\n", smartLabelFor(field))
|
w.Write(level, "%s:\n", smartLabelFor(field))
|
||||||
@ -340,7 +340,7 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
skipExpr := fmt.Sprintf("%s.%s", skipPrefix, field)
|
||||||
if slice.ContainsString(skip, skipExpr, nil) {
|
if slice.Contains[string](skip, skipExpr, nil) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w.Write(level, "%s:\t%v\n", smartLabelFor(field), typedValue)
|
w.Write(level, "%s:\t%v\n", smartLabelFor(field), typedValue)
|
||||||
@ -365,7 +365,7 @@ func smartLabelFor(field string) string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if slice.ContainsString(commonAcronyms, strings.ToUpper(part), nil) {
|
if slice.Contains[string](commonAcronyms, strings.ToUpper(part), nil) {
|
||||||
part = strings.ToUpper(part)
|
part = strings.ToUpper(part)
|
||||||
} else {
|
} else {
|
||||||
part = strings.Title(part)
|
part = strings.Title(part)
|
||||||
|
@ -23,8 +23,23 @@ import (
|
|||||||
// SortInts64 sorts []int64 in increasing order
|
// SortInts64 sorts []int64 in increasing order
|
||||||
func SortInts64(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
|
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.
|
// 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.
|
// 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 {
|
func ContainsString(slice []string, s string, modifier func(s string) string) bool {
|
||||||
for _, item := range slice {
|
for _, item := range slice {
|
||||||
if item == s {
|
if item == s {
|
||||||
|
Loading…
Reference in New Issue
Block a user