File tree 2 files changed +76
-0
lines changed
2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
"github.com/shawn1m/overture/core/matcher/full"
13
13
"github.com/shawn1m/overture/core/matcher/regex"
14
14
"github.com/shawn1m/overture/core/matcher/suffix"
15
+ "github.com/shawn1m/overture/core/matcher/mix"
15
16
16
17
"io/ioutil"
17
18
"net"
@@ -170,6 +171,8 @@ func getDomainMatcher(name string) (m matcher.Matcher) {
170
171
return & full.List {DataList : []string {}}
171
172
case "regex-list" :
172
173
return & regex.List {RegexList : []string {}}
174
+ case "mix-list" :
175
+ return & mix.List {DataList : make ([]mix.Data , 0 )}
173
176
default :
174
177
log .Warn ("There is no such matcher: " + name , ", use regex-list matcher as default" )
175
178
return & regex.List {RegexList : []string {}}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2019 shawn1m. All rights reserved.
3
+ * Use of this source code is governed by The MIT License (MIT) that can be
4
+ * found in the LICENSE file..
5
+ */
6
+
7
+ package mix
8
+
9
+ import (
10
+ "errors"
11
+ "regexp"
12
+ "strings"
13
+ )
14
+
15
+ type Data struct {
16
+ Type string
17
+ Content string
18
+ }
19
+
20
+ type List struct {
21
+ DataList []Data
22
+ }
23
+
24
+ func (s * List ) Insert (str string ) error {
25
+ kv := strings .Split (str , ":" )
26
+ if len (kv ) > 2 {
27
+ return errors .New ("Invalid format: " + str )
28
+ }
29
+ if len (kv ) == 1 {
30
+ s .DataList = append (s .DataList ,
31
+ Data {
32
+ Type : "domain" ,
33
+ Content : strings .ToLower (kv [0 ])})
34
+ }
35
+ if len (kv ) == 2 {
36
+ s .DataList = append (s .DataList ,
37
+ Data {
38
+ Type : strings .ToLower (kv [0 ]),
39
+ Content : strings .ToLower (kv [1 ])})
40
+ }
41
+
42
+ return nil
43
+ }
44
+
45
+ func (s * List ) Has (str string ) bool {
46
+ for _ , data := range s .DataList {
47
+ switch data .Type {
48
+ case "domain" :
49
+ idx := len (str ) - len (data .Content )
50
+ if idx > 0 && data .Content == str [idx :] {
51
+ return true
52
+ }
53
+ case "regex" :
54
+ reg := regexp .MustCompile (data .Content )
55
+ if reg .MatchString (str ) {
56
+ return true
57
+ }
58
+ case "keyword" :
59
+ if strings .Contains (str , data .Content ) {
60
+ return true
61
+ }
62
+ case "full" :
63
+ if data .Content == str {
64
+ return true
65
+ }
66
+ }
67
+ }
68
+ return false
69
+ }
70
+
71
+ func (s * List ) Name () string {
72
+ return "mix-list"
73
+ }
You can’t perform that action at this time.
0 commit comments