refact: use generics for contains functions

This commit is contained in:
Adrien Raffin-Caboisse 2022-04-25 21:50:40 +02:00
parent ea9aaa6022
commit 8061abe279
5 changed files with 14 additions and 22 deletions

View file

@ -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)
}
}

View file

@ -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
}
}