Exemple #1
0
// delRule delete a rule from the suffix tree
func (f *Filter) delRule(rule *models.Rule) {
	l := strings.Split(rule.Pattern, ".")
	if !f.children.Has(l[0]) {
		return
	}
	v, _ := f.children.Get(l[0])
	ch := v.(*childFilter)
	l = l[1:]
	for len(l) > 0 {
		if ch.children == nil {
			return
		}
		if ch.children.Has(l[0]) {
			v, _ = ch.children.Get(l[0])
			ch = v.(*childFilter)
		} else {
			return
		}
		l = l[1:]
	}
	ch.lock.Lock()
	defer ch.lock.Unlock()
	rules := []*models.Rule{}
	for _, r := range v.(*childFilter).matchedRules {
		if !rule.Equal(r) {
			rules = append(rules, r)
		}
	}
	ch.matchedRules = rules
}
Exemple #2
0
// Put a rule into cache.
func (c *rulesCache) Put(rule *models.Rule) bool {
	if c.rules.Has(rule.ID) {
		return false
	}
	r := rule.Copy()
	r.Share()
	c.rules.Set(rule.ID, r)
	c.pushAdded(rule)
	return true
}