refact: use generics for contains functions
This commit is contained in:
parent
ea9aaa6022
commit
8061abe279
5 changed files with 14 additions and 22 deletions
|
@ -372,12 +372,12 @@ func nodesToPtables(
|
|||
tags += "," + tag
|
||||
}
|
||||
for _, tag := range machine.InvalidTags {
|
||||
if !containsString(machine.ForcedTags, tag) {
|
||||
if !contains(machine.ForcedTags, tag) {
|
||||
tags += "," + pterm.LightRed(tag)
|
||||
}
|
||||
}
|
||||
for _, tag := range machine.ValidTags {
|
||||
if !containsString(machine.ForcedTags, tag) {
|
||||
if !contains(machine.ForcedTags, tag) {
|
||||
tags += "," + pterm.LightGreen(tag)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -565,9 +566,9 @@ func GetFileMode(key string) fs.FileMode {
|
|||
return fs.FileMode(mode)
|
||||
}
|
||||
|
||||
func containsString(ss []string, s string) bool {
|
||||
for _, v := range ss {
|
||||
if v == s {
|
||||
func contains[T string](ts []T, t T) bool {
|
||||
for _, v := range ts {
|
||||
if reflect.DeepEqual(v,t) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue