dns_cache

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

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

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

func New(db *gorm.DB, logger log.Logger) (*Cache, error)

New creates a dns_cache.Cache from the given GORM database connection. It automatically runs AutoMigrate for the DNSOverride table.

func (*Cache) Delete

func (c *Cache) Delete(lookupKey string) error

Delete removes a DNS override entry.

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

func (c *Cache) Resolve(ctx context.Context, key string) (string, error)

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.

func (*Cache) Set

func (c *Cache) Set(lookupKey, targetHost, comment string) error

Set creates or updates a DNS override entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL