/
util.go
61 lines (54 loc) · 1.04 KB
/
util.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
61
package assertion
import (
"path/filepath"
)
func unquoted(s string) string {
if s[0] == '"' {
return s[1 : len(s)-1]
}
return s
}
func isAbsent(s string) bool {
if s == "" || s == "null" || s == "[]" {
return true
}
return false
}
func isPresent(s string) bool {
return !isAbsent(s)
}
func listsIntersect(list1 []string, list2 []string) bool {
for _, a := range list1 {
for _, b := range list2 {
if a == b {
return true
}
}
}
return false
}
func ShouldIncludeFile(patterns []string, filename string) bool {
for _, pattern := range patterns {
_, file := filepath.Split(filename)
matched, err := filepath.Match(pattern, file)
if err != nil {
panic(err)
}
if matched {
return true
}
}
return false
}
func FilterResourcesByType(resources []Resource, resourceType string) []Resource {
if resourceType == "*" {
return resources
}
filtered := make([]Resource, 0)
for _, resource := range resources {
if resource.Type == resourceType {
filtered = append(filtered, resource)
}
}
return filtered
}