V2bX/limiter/rule.go

38 lines
722 B
Go
Raw Permalink Normal View History

package limiter
import (
"regexp"
2023-07-20 09:14:18 -04:00
2023-07-29 07:27:15 -04:00
"github.com/InazumaV/V2bX/api/panel"
)
func (l *Limiter) CheckDomainRule(destination string) (reject bool) {
// have rule
2023-07-20 09:14:18 -04:00
for i := range l.DomainRules {
if l.DomainRules[i].MatchString(destination) {
reject = true
break
}
}
return
}
func (l *Limiter) CheckProtocolRule(protocol string) (reject bool) {
for i := range l.ProtocolRules {
if l.ProtocolRules[i] == protocol {
reject = true
break
}
}
return
}
2023-07-20 09:14:18 -04:00
func (l *Limiter) UpdateRule(rule *panel.Rules) error {
l.DomainRules = make([]*regexp.Regexp, len(rule.Regexp))
for i := range rule.Regexp {
l.DomainRules[i] = regexp.MustCompile(rule.Regexp[i])
}
2023-07-20 09:14:18 -04:00
l.ProtocolRules = rule.Protocol
return nil
}