dns

package
v1.0.48 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDNSTimeout = 10 * time.Second

DefaultDNSTimeout is the default timeout for a DNS action which is 10 seconds

Variables

View Source
var ErrClosed = errors.New("closed")
View Source
var ErrInvalidIP = fmt.Errorf("invalid ip address resolved for hostname")
View Source
var ErrTimeout = errors.New("timeout")
View Source
var ErrTransportRequired = errors.New("transport is required")

Functions

func SendDNSAction added in v1.0.48

func SendDNSAction[R any, T DNSAction](ctx context.Context, action T, opts ...optionHandler) (*R, error)

SendDNSAction sends a DNS action to the DNS server with a timeout. If the timeout is 0, the default timeout will be used.

func WithRedis added in v1.0.48

func WithRedis(redis *redis.Client) optionHandler

WithRedis uses a redis client as the transport for the DNS action

func WithReply added in v1.0.48

func WithReply(reply bool) optionHandler

WithReply sets whether the DNS action should wait for a reply from the DNS server

func WithTimeout added in v1.0.48

func WithTimeout(timeout time.Duration) optionHandler

WithTimeout sets a custom timeout for the DNS action

func WithTransport added in v1.0.48

func WithTransport(transport Transport) optionHandler

WithTransport sets a custom transport for the DNS action

Types

type Answer

type Answer struct {
	Name string     `json:"name"`
	Type RecordType `json:"type"`
	TTL  uint       `json:"ttl"`
	Data string     `json:"data"`
}

type DNS

type DNS interface {
	// Lookup performs a DNS lookup for the given hostname and returns a valid IP address for the A record.
	Lookup(ctx context.Context, hostname string) (bool, *net.IP, error)
}

type DNSAction added in v1.0.48

type DNSAction interface {
	// GetID returns the unique ID of the DNS action
	GetID() string
	// GetReply returns the reply of the DNS action
	GetReply() string
	// SetReply sets the reply of the DNS action
	SetReply(string)
}

DNSAction is an interface for a DNS action

type DNSAddAction added in v1.0.48

type DNSAddAction struct {
	DNSBaseAction
	Name    string        `json:"name"`
	Type    string        `json:"type,omitempty"`
	Value   string        `json:"value,omitempty"`
	TTL     time.Duration `json:"ttl,omitempty"`
	Expires time.Duration `json:"expires,omitempty"`
	TLSCert string        `json:"tls_cert,omitempty"`
}

func AddDNSAction added in v1.0.48

func AddDNSAction(name string, recordType DNSRecordType, value string, ttl time.Duration, expires time.Duration, tlsCert string) *DNSAddAction

AddDNSAction adds a DNS action to the DNS server

type DNSBaseAction added in v1.0.48

type DNSBaseAction struct {
	ID     string `json:"id"`
	Action string `json:"action"`
	Reply  string `json:"reply,omitempty"`
}

func (DNSBaseAction) GetID added in v1.0.48

func (a DNSBaseAction) GetID() string

GetID returns the unique ID of the DNS action

func (DNSBaseAction) GetReply added in v1.0.48

func (a DNSBaseAction) GetReply() string

GetReply returns the reply of the DNS action

func (*DNSBaseAction) SetReply added in v1.0.48

func (a *DNSBaseAction) SetReply(reply string)

SetReply sets the reply of the DNS action

type DNSCert added in v1.0.48

type DNSCert struct {
	Certificate []byte    `json:"certificate"`
	PrivateKey  []byte    `json:"private_key"`
	Expires     time.Time `json:"expires"`
}

type DNSCertAction added in v1.0.48

type DNSCertAction struct {
	DNSBaseAction
	Name string `json:"name"`
}

func CertRequestDNSAction added in v1.0.48

func CertRequestDNSAction(name string) *DNSCertAction

CertRequestDNSAction requests a certificate from the DNS server

type DNSCertResponse added in v1.0.48

type DNSCertResponse struct {
	DNSResponse[DNSCert]
}

type DNSDeleteAction added in v1.0.48

type DNSDeleteAction struct {
	DNSBaseAction
	Name string `json:"name"`
}

func DeleteDNSAction added in v1.0.48

func DeleteDNSAction(name string) *DNSDeleteAction

DeleteDNSAction deletes a DNS action from the DNS server

type DNSRecordType added in v1.0.48

type DNSRecordType string
const (
	RecordTypeA     DNSRecordType = "A"
	RecordTypeAAAA  DNSRecordType = "AAAA"
	RecordTypeCNAME DNSRecordType = "CNAME"
	RecordTypeMX    DNSRecordType = "MX"
	RecordTypeNS    DNSRecordType = "NS"
	RecordTypeTXT   DNSRecordType = "TXT"
)

type DNSResponse added in v1.0.48

type DNSResponse[T any] struct {
	ID      string `json:"id"`
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
	Data    *T     `json:"data,omitempty"`
}

type Dns

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

func New

func New(cache cache.Cache, opts ...WithConfig) *Dns

New creates a new DNS caching resolver.

func (*Dns) Lookup

func (d *Dns) Lookup(ctx context.Context, hostname string) (bool, *net.IP, error)

Lookup performs a DNS lookup for the given hostname and returns a valid IP address for the A record.

type Message added in v1.0.48

type Message struct {
	Payload []byte
}

Message is a message from the transport layer

type RecordType

type RecordType uint8
const (
	A     RecordType = 1
	CNAME RecordType = 5
)

type Result

type Result struct {
	Status StatusType `json:"Status"`
	Answer []Answer   `json:"Answer"`
}

type StatusType

type StatusType uint8
const (
	NoError  StatusType = 0
	FormErr  StatusType = 1
	ServFail StatusType = 2
	NXDomain StatusType = 3
	Refused  StatusType = 5
	NotAuth  StatusType = 9
	NotZone  StatusType = 10
)

func (StatusType) String

func (s StatusType) String() string

type Subscriber added in v1.0.48

type Subscriber interface {
	// Close closes the subscriber
	Close() error
	// Channel returns a channel of messages
	Channel() <-chan *Message
}

Subscriber is an interface for a subscriber to the transport layer

type Transport added in v1.0.48

type Transport interface {
	Subscribe(ctx context.Context, channel string) Subscriber
	Publish(ctx context.Context, channel string, payload []byte) error
}

Transport is an interface for a transport layer for the DNS server

type WithConfig

type WithConfig func(config *dnsConfig)

func WithFailIfLocal

func WithFailIfLocal() WithConfig

WithFailIfLocal will cause the DNS resolver to fail if the hostname is a local hostname.

Jump to

Keyboard shortcuts

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