Files
ctrld/internal/rulematcher/types.go
Cuong Manh Le d42a78cba9 docs: add comprehensive package documentation for rulematcher
- 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.
2025-10-09 19:12:06 +07:00

53 lines
1.2 KiB
Go

package rulematcher
import (
"context"
"net"
"github.com/Control-D-Inc/ctrld"
)
// RuleType represents the type of rule being matched
type RuleType string
const (
RuleTypeNetwork RuleType = "network"
RuleTypeMac RuleType = "mac"
RuleTypeDomain RuleType = "domain"
)
// RuleMatcher defines the interface for matching different types of rules
type RuleMatcher interface {
Match(ctx context.Context, request *MatchRequest) *MatchResult
}
// MatchRequest contains all the information needed for rule matching
type MatchRequest struct {
SourceIP net.IP
SourceMac string
Domain string
Policy *ctrld.ListenerPolicyConfig
Config *ctrld.Config
}
// MatchResult represents the result of a rule matching operation
type MatchResult struct {
Matched bool
Targets []string
MatchedRule string
RuleType RuleType
}
// MatchingConfig defines the configuration for rule matching behavior
type MatchingConfig struct {
Order []RuleType `json:"order" yaml:"order"`
}
// DefaultMatchingConfig returns the default matching configuration
// This maintains backward compatibility with the current behavior
func DefaultMatchingConfig() *MatchingConfig {
return &MatchingConfig{
Order: []RuleType{RuleTypeNetwork, RuleTypeMac, RuleTypeDomain},
}
}