-
Notifications
You must be signed in to change notification settings - Fork 2
/
ruleset.go
50 lines (41 loc) · 1.35 KB
/
ruleset.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
package httpseverywhere
import "regexp"
// Target is the target host for a given rule.
type Target struct {
Host string `xml:"host,attr"`
}
// Exclusion is a RE pattern to ignore when processing a rule set.
type Exclusion struct {
Pattern string `xml:"pattern,attr"`
}
// Rule is a rule to apply when processing a URL.
type Rule struct {
From string `xml:"from,attr"`
To string `xml:"to,attr"`
}
// Ruleset is a set of rules to apply to a set of targets with flags for things
// like whether or not the set is active, targets, rules, exclusions, etc.
type Ruleset struct {
Off string `xml:"default_off,attr"`
Platform string `xml:"platform,attr"`
Target []*Target `xml:"target"`
Exclusion []*Exclusion `xml:"exclusion"`
Rule []*Rule `xml:"rule"`
}
// The below types are simplified in-memory representations for what we
// actually need at runtime after rules have been deserialized.
// exclusion is a RE pattern to ignore when processing a rule set.
type exclusion struct {
pattern *regexp.Regexp
}
// rule is a rule to apply when processing a URL.
type rule struct {
from *regexp.Regexp
to string
}
// ruleset is a set of rules to apply to a set of targets with flags for things
// like whether or not the set is active, targets, rules, exclusions, etc.
type ruleset struct {
exclusion []exclusion
rule []rule
}