forked from wendigo/chrome-protocol-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
52 lines (40 loc) · 1.02 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
package main
import (
"flag"
"fmt"
"strings"
)
type argumentList struct {
name string
values []string
}
func (al *argumentList) String() string {
return fmt.Sprintf("%s = %s", al.name, strings.Join(al.values, ", "))
}
func (al *argumentList) Set(value string) error {
al.values = append(al.values, value)
return nil
}
var filterInclude = &argumentList{name: "include", values: []string{}}
var filterExclude = &argumentList{name: "exclude", values: []string{}}
func init() {
flag.Var(filterInclude, "include", "display only requests/responses/events matching pattern")
flag.Var(filterExclude, "exclude", "exclude requests/responses/events matching pattern")
}
func accept(values ...string) bool {
value := strings.Join(values, "")
for _, exclude := range filterExclude.values {
if strings.Contains(value, exclude) {
return false
}
}
if len(filterInclude.values) == 0 {
return true
}
for _, include := range filterInclude.values {
if strings.Contains(value, include) {
return true
}
}
return false
}