dnsring

package module
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Unlicense Imports: 7 Imported by: 0

README

dnsring

Ring of DNS servers for spreading IP lookups over multiple DNS servers. Uses an in-memory cache to avoid repeated lookups. Only returns the first IP if matches and prefers IPv4 over IPv6.

Usage Example

    DNSRing := dnsring.New(dns.NewServer("8.8.8.8", 53, 2000), dns.NewServer("8.8.4.4", 53, 2000))
    host := "google.com"
	ip := DNSRing.Next().HostToIP(host)
	if ip == "" {
        fmt.Printf("%s did not resolve to an IP\n", host)
	} else {
        fmt.Printf("%s has the IP: %s\n", host, ip)
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCacheExclusions

func AddCacheExclusions(exclusions map[string]string)

Types

type Cache

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

type Resolver

type Resolver struct {
	Host     string        `yaml:"host"`
	Port     uint          `yaml:"port"`
	Resolver *net.Resolver `yaml:"-"`
}

func NewResolver

func NewResolver(host string, port uint, timeout time.Duration) *Resolver

func (*Resolver) HostToIP

func (dr *Resolver) HostToIP(host string) string

type Ring

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

func New

func New(servers ...Server) *Ring

func (*Ring) Next

func (rs *Ring) Next() *Resolver

type Server

type Server struct {
	Host    string `yaml:"host"`
	Port    int    `yaml:"port"`
	Timeout int    `yaml:"timeout"`
}

func NewServer

func NewServer(host string, port, timeout int) *Server

Jump to

Keyboard shortcuts

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