This commit is contained in:
jdl
2024-11-11 06:36:55 +01:00
parent d0587cc585
commit c5419d662e
102 changed files with 4181 additions and 0 deletions

58
tagengine/rulegroup.go Normal file
View File

@@ -0,0 +1,58 @@
package tagengine
// A RuleGroup can be converted into a list of rules. Each rule will point to
// the same tag, and have the same exclude set and blocks.
type RuleGroup struct {
Tag string
Includes [][]string
Excludes []string
Blocks []string
}
func NewRuleGroup(tag string) RuleGroup {
return RuleGroup{
Tag: tag,
Includes: [][]string{},
Excludes: []string{},
Blocks: []string{},
}
}
func (g RuleGroup) Inc(l ...string) RuleGroup {
return RuleGroup{
Tag: g.Tag,
Includes: append(g.Includes, l),
Excludes: g.Excludes,
Blocks: g.Blocks,
}
}
func (g RuleGroup) Exc(l ...string) RuleGroup {
return RuleGroup{
Tag: g.Tag,
Includes: g.Includes,
Excludes: append(g.Excludes, l...),
Blocks: g.Blocks,
}
}
func (g RuleGroup) Block(l ...string) RuleGroup {
return RuleGroup{
Tag: g.Tag,
Includes: g.Includes,
Excludes: g.Excludes,
Blocks: append(g.Blocks, l...),
}
}
func (g RuleGroup) ToList() (l []Rule) {
for _, includes := range g.Includes {
l = append(l, Rule{
Tag: g.Tag,
Excludes: g.Excludes,
Includes: includes,
Blocks: g.Blocks,
})
}
return
}