-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblacklist.go
48 lines (39 loc) · 914 Bytes
/
blacklist.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
package main
import (
_ "embed"
"encoding/json"
mapset "github.com/deckarep/golang-set/v2"
"strings"
)
//go:embed resource/blacklist.json
var fileByte []byte
func filter(data []Data) ([]Data, error) {
var blacklist Blacklist
if err := json.Unmarshal(fileByte, &blacklist); err != nil {
return nil, err
}
authors := mapset.NewThreadUnsafeSet(blacklist.Authors...)
categories := mapset.NewThreadUnsafeSet(blacklist.Categories...)
var ret []Data
Loop:
for _, datum := range data {
if authors.Contains(datum.Owner.Name) {
continue
}
if categories.Contains(datum.Tname) {
continue
}
for _, keyword := range blacklist.Keywords {
if strings.Contains(datum.Title, keyword) || strings.Contains(datum.Desc, keyword) {
continue Loop
}
}
ret = append(ret, datum)
}
return ret, nil
}
type Blacklist struct {
Authors []string
Categories []string
Keywords []string
}