dns

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

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 provides TTL-aware DNS caching

func NewCache

func NewCache() *Cache

NewCache creates a new DNS cache

func (*Cache) Cleanup

func (c *Cache) Cleanup()

Cleanup removes expired entries from the cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from the cache

func (*Cache) Invalidate

func (c *Cache) Invalidate(host string)

Invalidate removes a hostname from the cache

func (*Cache) Resolve

func (c *Cache) Resolve(ctx context.Context, host string) ([]net.IP, error)

Resolve looks up the IP addresses for a hostname Returns cached result if available and not expired

func (*Cache) ResolveAllSorted

func (c *Cache) ResolveAllSorted(ctx context.Context, host string) ([]net.IP, error)

ResolveAllSorted returns all IPs sorted for Happy Eyeballs (RFC 8305) IPv6 addresses first, interleaved with IPv4

func (*Cache) ResolveIPv6First

func (c *Cache) ResolveIPv6First(ctx context.Context, host string) (ipv6 []net.IP, ipv4 []net.IP, err error)

ResolveIPv6First returns IPv6 addresses first, then IPv4 addresses This is for strict IPv6 preference - try all IPv6 before falling back to IPv4

func (*Cache) ResolveOne

func (c *Cache) ResolveOne(ctx context.Context, host string) (net.IP, error)

ResolveOne returns a single IP address for the hostname Prefers IPv6 over IPv4 (modern browser behavior)

func (*Cache) SetTTL

func (c *Cache) SetTTL(ttl time.Duration)

SetTTL sets the default TTL for cached entries

func (*Cache) StartCleanup

func (c *Cache) StartCleanup(ctx context.Context, interval time.Duration)

StartCleanup starts a background goroutine that periodically cleans up expired entries

func (*Cache) Stats

func (c *Cache) Stats() (total int, expired int)

Stats returns cache statistics

type Entry

type Entry struct {
	IPs       []net.IP
	ExpiresAt time.Time
	LookupAt  time.Time
}

Entry represents a cached DNS entry

func (*Entry) IsExpired

func (e *Entry) IsExpired() bool

IsExpired checks if the entry has expired

Jump to

Keyboard shortcuts

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