/
utils.go
60 lines (49 loc) · 1.32 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package controllers
import (
"sort"
"time"
)
// filter removes namespaces from the list that match the denied namespaces.
func filter(namespaces []string, deniedNamespaces []string) []string {
filteredNamespaces := make([]string, 0)
for _, ns := range namespaces {
// Check if the namespace is not in the denied namespaces list
if !contains(deniedNamespaces, ns) {
filteredNamespaces = append(filteredNamespaces, ns)
}
}
return filteredNamespaces
}
// contains checks if a string exists in a slice of strings.
func contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}
// getCurrentTimeString returns the current time as a string using the specified layout.
func getCurrentTimeString() string {
// Get the current time
currentTime := time.Now()
// Convert time to string using the specified layout
timeString := currentTime.Format("2006-01-02 15:04:05")
return timeString
}
func compareSlices(slice1, slice2 []int) bool {
// Check if the slices have different lengths
if len(slice1) != len(slice2) {
return false
}
sort.Ints(slice1)
sort.Ints(slice2)
// Iterate over each element of the slices and compare them
for i := range slice1 {
if slice1[i] != slice2[i] {
return false
}
}
// If all elements are equal, return true
return true
}