mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-03-13 10:26:06 +00:00
- Add detailed package documentation to engine.go explaining the rule matching system, supported rule types (Network, MAC, Domain), and priority ordering - Include usage example demonstrating typical API usage patterns - Remove unused Type() method from RuleMatcher interface and implementations - Maintain backward compatibility while improving code documentation The documentation explains the policy-based DNS routing system and how different rule types interact with configurable priority ordering.
32 lines
846 B
Go
32 lines
846 B
Go
package rulematcher
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// DomainRuleMatcher handles matching of domain-based rules
|
|
type DomainRuleMatcher struct{}
|
|
|
|
// Match evaluates domain rules against the requested domain
|
|
func (d *DomainRuleMatcher) Match(ctx context.Context, req *MatchRequest) *MatchResult {
|
|
if req.Policy == nil || len(req.Policy.Rules) == 0 {
|
|
return &MatchResult{Matched: false, RuleType: RuleTypeDomain}
|
|
}
|
|
|
|
for _, rule := range req.Policy.Rules {
|
|
// There's only one entry per rule, config validation ensures this.
|
|
for source, targets := range rule {
|
|
if source == req.Domain || wildcardMatches(source, req.Domain) {
|
|
return &MatchResult{
|
|
Matched: true,
|
|
Targets: targets,
|
|
MatchedRule: source,
|
|
RuleType: RuleTypeDomain,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return &MatchResult{Matched: false, RuleType: RuleTypeDomain}
|
|
}
|