dns

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package dns provides DNS caching functionality to reduce lookup latency and improve performance for repeated connections to the same hosts.

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 DNS lookup caching with TTL-based expiration. It reduces DNS lookup latency for repeated requests to the same hosts.

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache creates a new DNS cache with the specified TTL. If ttl is 0, defaults to 5 minutes.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all cached entries.

func (*Cache) LookupIP

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

LookupIP resolves host to IP addresses, using cached results if available.

func (*Cache) LookupIPAddr

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

LookupIPAddr resolves host to IP addresses as net.IPAddr.

func (*Cache) Size

func (c *Cache) Size() int

Size returns the approximate number of cached entries.

type CachedDialer

type CachedDialer struct {
	// contains filtered or unexported fields
}

CachedDialer wraps a net.Dialer with DNS caching.

func NewCachedDialer

func NewCachedDialer(dialer *net.Dialer, cache *Cache) *CachedDialer

NewCachedDialer creates a new dialer with DNS caching.

func (*CachedDialer) DialContext

func (d *CachedDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext dials using cached DNS lookups.

Jump to

Keyboard shortcuts

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