MagiTrickle/models/domain.go

34 lines
529 B
Go
Raw Normal View History

2024-08-26 19:10:40 +03:00
package models
2024-08-26 19:34:45 +03:00
import (
"regexp"
"github.com/IGLOU-EU/go-wildcard/v2"
)
2024-08-26 19:10:40 +03:00
type Domain struct {
ID int
Group *Group
Type string
Domain string
Enable bool
Comment string
}
2024-08-26 19:34:45 +03:00
func (d *Domain) IsEnabled() bool {
return d.Enable
}
func (d *Domain) IsMatch(domainName string) bool {
switch d.Type {
case "wildcard":
return wildcard.Match(d.Domain, domainName)
case "regex":
ok, _ := regexp.MatchString(d.Domain, domainName)
return ok
case "plaintext":
return domainName == d.Domain
}
return false
}