dns

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PolicyFirst = iota
	PolicyRandom
	PolicyRoundRobin
)
View Source
const (
	NetworkIP = iota
	NetworkIPV4
	NetworkIPV6
)

Variables

View Source
var ErrNotFound = errors.New("Not Found")

Functions

This section is empty.

Types

type Cache added in v1.0.4

type Cache struct {
	Storage  Storage
	TTL      time.Duration
	Stale    time.Duration
	OnStats  OnStats
	Dialer   *net.Dialer
	Resolver *net.Resolver
	Policy   int
	Network  int
	Timeout  time.Duration
	// contains filtered or unexported fields
}

Cache dns cache

func New added in v1.0.4

func New(ttl time.Duration, opts ...CacheOption) *Cache

New create a dns cache instance

func (*Cache) Delete added in v1.0.4

func (c *Cache) Delete(ctx context.Context, host string) error

Removes cache of host

func (*Cache) Get added in v1.0.4

func (c *Cache) Get(ctx context.Context, host string) (IPCache, error)

Gets ip cache of host

func (*Cache) GetDialContext added in v1.0.4

func (c *Cache) GetDialContext(retryDialIfCacheFail ...bool) func(context.Context, string, string) (net.Conn, error)

GetDialContext get dial context function with cache

func (*Cache) Lookup added in v1.0.4

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

Lookup lookup

func (*Cache) LookupWithCache added in v1.0.4

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

LookupWithCache lookup with cache

func (*Cache) Set added in v1.0.4

func (c *Cache) Set(ctx context.Context, host string, ipCache IPCache) error

Sets ip cache for the host

type CacheOption added in v1.0.4

type CacheOption func(*Cache)

func DialerOption added in v1.0.4

func DialerOption(dialer *net.Dialer) CacheOption

DialerOption sets dialer

func NetworkOption added in v1.0.4

func NetworkOption(network int) CacheOption

NetworkOption set network option

func OnStatsOption added in v1.0.4

func OnStatsOption(onStats OnStats) CacheOption

OnStatsOption sets on stats function

func PolicyOption added in v1.0.4

func PolicyOption(policy int) CacheOption

PolicyOption sets policy

func ResolverOption added in v1.0.4

func ResolverOption(resolver *net.Resolver) CacheOption

ResolverOption sets resolver

func StaleOption added in v1.0.4

func StaleOption(stale time.Duration) CacheOption

StaleOption sets stale

func StorageOption added in v1.0.4

func StorageOption(storage Storage) CacheOption

StorageOption sets storage

func TimeoutOption added in v1.0.4

func TimeoutOption(value time.Duration) CacheOption

TimeoutOption set timeout option

type IPCache added in v1.0.4

type IPCache struct {
	IPAddrs   []net.IP
	CreatedAt time.Time
}

IPCache ip cache

type OnStats added in v1.0.4

type OnStats func(host string, d time.Duration, ipAddrs []string)

OnStats on stats function

type Storage added in v1.0.4

type Storage interface {
	Set(ctx context.Context, host string, ipCache IPCache, ttl time.Duration) error
	Delete(ctx context.Context, host string) error
	Get(ctx context.Context, host string) (IPCache, error)
}

Jump to

Keyboard shortcuts

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