-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
62 lines (58 loc) · 1.47 KB
/
filter.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
62
// Copyright (c) 2023 Julian Müller (ChaoticByte)
package main
import (
"strings"
)
type Filter struct {
Any bool `json:"any"`
TitleContains string `json:"title_contains"`
Classification string `json:"classification"`
MinBaseScore int `json:"min_basescore"`
Status string `json:"status"`
ProductsContain string `json:"products_contain"`
NoPatch string `json:"no_patch"`
ApiEndpointId string `json:"api_endpoint"`
}
func (f Filter) filter(notices []WidNotice) []WidNotice {
filteredNotices := []WidNotice{}
for _, n := range notices {
matches := []bool{}
if f.Any {
matches = append(matches, true)
} else
{
if f.TitleContains != "" {
matches = append(matches, strings.Contains(n.Title, f.TitleContains))
}
if f.Classification != "" {
matches = append(matches, f.Classification == n.Classification)
}
if f.MinBaseScore > 0 {
matches = append(matches, f.MinBaseScore <= n.Basescore)
}
if f.Status != "" {
matches = append(matches, f.Status == n.Status)
}
if f.ProductsContain != "" {
matches = append(matches, len(n.ProductNames) > 0)
}
if f.NoPatch != "" {
matches = append(matches, f.NoPatch == n.NoPatch)
}
if f.ApiEndpointId != "" {
matches = append(matches, f.ApiEndpointId == n.ApiEndpointId)
}
}
allMatch := len(matches) > 0
for _, m := range matches {
if !m {
allMatch = false
break
}
}
if allMatch {
filteredNotices = append(filteredNotices, n)
}
}
return filteredNotices
}