-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruleset.go
40 lines (34 loc) · 944 Bytes
/
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
// +build !windows,!plan9,!linux
package pf
import "strings"
// RuleSet represents a set of firewall rules
type RuleSet struct {
Rules []Rule
}
// AddRule adds a given rule to the RuleSet struct rules array. The rule must have the committed
// flag set to true
func (rs *RuleSet) AddRule(r Rule) {
if r.committed {
rs.Rules = append(rs.Rules, r)
}
}
// GetRules returns a string array of all committed rules of the current RuleSet
func (rs *RuleSet) GetRules() []string {
ruleArray := make([]string, 0)
for _, r := range rs.Rules {
if r.committed {
ruleArray = append(ruleArray, r.String())
}
}
return ruleArray
}
// RulesString returns a line separated string of all committed rules of the current RuleSet
func (rs *RuleSet) RulesString() string {
ruleArray := make([]string, 0)
for _, r := range rs.Rules {
if r.committed {
ruleArray = append(ruleArray, r.String())
}
}
return strings.Join(ruleArray, "\n")
}