Documentation
¶
Index ¶
- func DefaultFreeProviders() map[string]struct{}
- type BloomOptions
- type Options
- type ValidationResult
- type Validator
- func (v *Validator) IsValid(email string) bool
- func (v *Validator) LoadBloomFilter(r io.Reader) error
- func (v *Validator) LoadDisposableDomains(urlStr string) error
- func (v *Validator) LoadFreeProviders(urlStr string) error
- func (v *Validator) LoadTrustedDomains(urlStr string) error
- func (v *Validator) RegisterDisposableDomains(domains []string)
- func (v *Validator) RegisterFreeProviders(providers []string)
- func (v *Validator) RegisterTrustedDomains(domains []string)
- func (v *Validator) SaveBloomFilter(w io.Writer) error
- func (v *Validator) UseBloomFilter(url string, opts BloomOptions) error
- func (v *Validator) Validate(email string) ValidationResult
- func (v *Validator) ValidateMany(emails []string) []ValidationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFreeProviders ¶
func DefaultFreeProviders() map[string]struct{}
DefaultFreeProviders returns the default free email providers
Types ¶
type BloomOptions ¶ added in v0.0.4
type BloomOptions struct {
// FalsePositiveRate sets the desired false positive rate (0.0 to 1.0)
// Lower values use more memory but have fewer false positives
FalsePositiveRate float64
// VerificationAttempts reduces false positives exponentially by checking
// the domain multiple times with different hash functions. Each check must
// return "probably in set" for the domain to be considered disposable.
// The actual false positive rate becomes FalsePositiveRate^VerificationAttempts.
//
// Examples with FalsePositiveRate = 0.01 (1%):
// - 1 attempt: 1% false positives (0.01^1)
// - 2 attempts: 0.01% false positives (0.01^2)
// - 3 attempts: 0.0001% false positives (0.01^3)
//
// Higher values provide better accuracy at the cost of more CPU time.
// Default is 1.
VerificationAttempts int
}
BloomOptions configures the bloom filter behavior
func DefaultBloomOptions ¶ added in v0.0.4
func DefaultBloomOptions() BloomOptions
DefaultBloomOptions returns sensible defaults
type Options ¶
type Options struct {
CheckDNS bool // Whether to perform DNS MX lookup
CheckDisposable bool // Whether to check for disposable domains
CheckFreeProvider bool // Whether to check for free email providers
DNSCacheTTL time.Duration // TTL for DNS cache
DNSCacheSize int // Maximum number of DNS cache entries
DNSTimeout time.Duration // Timeout for DNS lookups
DisposableDomainsURL string // URL for disposable domains list
FreeProvidersURL string // URL for free email providers list
MaxEmailLength int // Maximum email length
MinDomainLength int // Minimum domain length
RejectDisposable bool // Whether to invalidate disposable domains
RejectFreeProvider bool // Whether to invalidate free email providers
RejectIPDomains bool // Whether to reject IP address domains
RejectNamedEmails bool // Whether to reject named email addresses (e.g. "First Last <first.last@example.com>")
RejectReserved bool // Whether to invalidate reserved example domains
TrustedDomainsURL string // URL for trusted domains list
}
Options contains configuration options for email validation
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the default validator options
type ValidationResult ¶
type ValidationResult struct {
Address string // Normalized email address
IsDisposable bool // Whether the domain is disposable
IsFreeProvider bool // Whether the domain is a free provider
IsIPDomain bool // Whether the domain is an IP address
IsReserved bool // Whether the domain is reserved
IsValid bool // Whether the email is valid
LastError error // Validation error
Name string // Parsed name from email
Original string // Original email address input
ValidationTime time.Duration // Time taken to validate
}
func (ValidationResult) ErrorMessage ¶ added in v0.0.3
func (vr ValidationResult) ErrorMessage() string
ErrorMessage returns the last validation error as a string if present, otherwise an empty string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func (*Validator) IsValid ¶ added in v0.0.5
IsValid checks if an email address is valid and immediately returns a boolean
func (*Validator) LoadBloomFilter ¶ added in v0.0.4
LoadBloomFilter deserializes the bloom filter from the provided reader
func (*Validator) LoadDisposableDomains ¶
LoadDisposableDomains loads domains from a JSON array into either the map or bloom filter, depending on which implementation is being used
func (*Validator) LoadFreeProviders ¶
LoadFreeProviders loads a list of free email providers from a JSON file or URL
func (*Validator) LoadTrustedDomains ¶ added in v0.0.4
LoadTrustedDomains loads a list of trusted domains from a JSON file or URL
func (*Validator) RegisterDisposableDomains ¶
RegisterDisposableDomains adds domains to either the map or bloom filter
func (*Validator) RegisterFreeProviders ¶
RegisterFreeProviders manually adds domains to the free providers list
func (*Validator) RegisterTrustedDomains ¶ added in v0.0.4
RegisterTrustedDomains adds trusted domains that are never considered disposable
func (*Validator) SaveBloomFilter ¶ added in v0.0.4
SaveBloomFilter serializes the bloom filter to the provided writer
func (*Validator) UseBloomFilter ¶ added in v0.0.4
func (v *Validator) UseBloomFilter(url string, opts BloomOptions) error
UseBloomFilter converts the validator to use a bloom filter instead of a map for disposable domain checking. This can significantly reduce memory usage. The expectedItems parameter should be set to the approximate number of disposable domains you expect to add to the filter.
func (*Validator) Validate ¶
func (v *Validator) Validate(email string) ValidationResult
Validate checks a single email address
func (*Validator) ValidateMany ¶
func (v *Validator) ValidateMany(emails []string) []ValidationResult
ValidateMany validates multiple email addresses concurrently