Documentation
¶
Overview ¶
Package dns_cache implements a database-backed DNS override cache.
When resolving a domain or IP for outbound mail delivery, the cache is consulted first. If a matching DNSOverride row exists in the database, its TargetHost is returned without performing any real DNS lookup. Otherwise the system's standard DNS resolver is used.
This allows operators to:
- Route mail destined for a domain to a specific IP (e.g., during migration).
- Override IP-literal destinations (e.g., a@[1.1.1.1] → deliver to 2.2.2.2).
- Test mail flows against staging servers without touching system DNS.
Index ¶
- type Cache
- func (c *Cache) Delete(lookupKey string) error
- func (c *Cache) Get(lookupKey string) (*mdb.DNSOverride, error)
- func (c *Cache) List() ([]mdb.DNSOverride, error)
- func (c *Cache) Resolve(ctx context.Context, key string) (string, error)
- func (c *Cache) ResolveMX(ctx context.Context, domain string) (records []*net.MX, cacheHit bool, err error)
- func (c *Cache) Set(lookupKey, targetHost, comment string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache wraps a GORM database to provide DNS resolution with local overrides.
func New ¶
New creates a dns_cache.Cache from the given GORM database connection. It automatically runs AutoMigrate for the DNSOverride table.
func (*Cache) Get ¶
func (c *Cache) Get(lookupKey string) (*mdb.DNSOverride, error)
Get retrieves a single DNS override entry.
func (*Cache) List ¶
func (c *Cache) List() ([]mdb.DNSOverride, error)
List returns all DNS override entries.
func (*Cache) Resolve ¶
Resolve looks up the target host for the given key (domain name or IP).
It ONLY returns a result when there is an explicit override in the database. If no override exists, it returns an empty string so the caller uses the original hostname for connecting (which preserves proper TLS certificate verification and MTA-STS compatibility).
func (*Cache) ResolveMX ¶
func (c *Cache) ResolveMX(ctx context.Context, domain string) (records []*net.MX, cacheHit bool, err error)
ResolveMX resolves the MX host for a domain. It first checks the local override database. If an override exists for the domain, it returns a single synthetic MX record pointing to the override target with cacheHit=true. Otherwise it performs a standard MX lookup via the OS resolver and returns cacheHit=false.