client

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package client implements DNS client wrappers

Index

Constants

View Source
const (
	// DefaultSingleFlightExpiration tells how long will we cache
	// the result after an exchange
	DefaultSingleFlightExpiration = 1 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	ExchangeContext(context.Context, *dns.Msg, string) (*dns.Msg, time.Duration, error)
}

A Client makes a request to a server

func NewDefaultClient

func NewDefaultClient() Client

NewDefaultClient allocate a default dns.Client in the same manner as dns.ExchangeContext(), plain UDP.

type SingleFlight

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

SingleFlight wraps a Client to minimize redundant queries

func NewSingleFlight

func NewSingleFlight(c Client, exp time.Duration) *SingleFlight

NewSingleFlight creates a SingleFlight Client around another. if no Client is specified, the default udp dns.Client will be used. if exp is positive, the result will be cached that long. if exp is negative, the result will expire immediately if exp is zero, DefaultSingleFlightExpiration will be used

func (*SingleFlight) ExchangeContext

func (sfc *SingleFlight) ExchangeContext(ctx context.Context, req *dns.Msg,
	server string) (*dns.Msg, time.Duration, error)

ExchangeContext makes a DNS query to a server, minimizing duplications.

func (*SingleFlight) RequestKey

func (*SingleFlight) RequestKey(req *dns.Msg, server string) string

RequestKey serializes a DNS request to act as temporary cache key

Jump to

Keyboard shortcuts

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