package rules import ( "context" "fmt" ) // HostnameRule matches URLs based on hostname/domain type HostnameRule struct { Hostname string `json:"hostname"` // Pattern like "example.com" or "*.github.com" Archivers []ArchiverConfig `json:"extractors,omitempty"` // Optional: only present on root rules, can be null for child rules (JSON tag kept for backward compatibility) } // Matches evaluates if the URL metadata matches the hostname pattern func (r *HostnameRule) Matches(ctx context.Context, metadata *URLMetadata) ([]ArchiverConfig, error) { if r.Hostname == "" { return nil, nil } // Compare domain with pattern if matchesPattern(r.Hostname, metadata.Domain) { // Return empty slice if Archivers is nil (for child rules in AND/OR) if r.Archivers == nil { return []ArchiverConfig{}, nil } return r.Archivers, nil } return nil, nil } // IsValid validates that the rule is properly defined func (r *HostnameRule) IsValid() error { if r.Hostname == "" { return fmt.Errorf("hostname rule: matches field is required") } return nil }