dnsregistry

package
v0.0.0-...-3b62d95 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Localhost should be provided to the DNSRegistry constructor as the
	// value for host when using the DNSRegistry in single-node implementations,
	// in-meomry implementations, or tests.
	Localhost    = "localhost"
	LocalAddress = "127.0.0.1"

	DNSServerID          = "DNS_SERVER_ID"
	DNSServerVersion     = int64(-1)
	DNS_ACTOR_GENERATION = 1
	// Must be at least 1 because <= 0 is not a legal versionstamp
	DNSVersionStamp = 1
)

Variables

This section is empty.

Functions

func NewDNSRegistry

func NewDNSRegistry(
	host string,
	port int,
	opts DNSRegistryOptions,
) (registry.Registry, error)

NewDNSRegistry creates a new registry.Registry backed by DNS.

func NewDNSRegistryFromResolver

func NewDNSRegistryFromResolver(
	resolver DNSResolver,
	host string,
	opts DNSRegistryOptions,
) (registry.Registry, error)

NewDNSRegistryFromResolver is the same as NewDNSRegistry except it allows a custom implementation of DNSResolver to be provided.

Types

type DNSRegistryOptions

type DNSRegistryOptions struct {
	// ResolveEvery controls how often the LookupIP method will be
	// called on the DNSResolver to detect which IPs are active.
	ResolveEvery time.Duration
	// Logger is a logging instance used for logging messages.
	// If no logger is provided, the default logger from the slog package (slog.Default()) will be used.
	Logger *slog.Logger
}

DNSRegistryOptions contains the options for the DNS resgistry implementation.

type DNSResolver

type DNSResolver interface {
	LookupIP(host string) ([]registry.Address, error)
}

DNSResolver is the interface that must be implemented by a resolver in order to map a hostname to set of live IPs.

func NewDNSResolver

func NewDNSResolver(port int) DNSResolver

NewDNSResolver returns a new DNSResolver that is backed by the standard library implementation of net.LookupIP.

type Hash

type Hash func(data []byte) uint32

type HashRing

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

func NewHashRing

func NewHashRing(replicas int, fn Hash) *HashRing

func (*HashRing) Add

func (m *HashRing) Add(keys ...string)

Add adds some keys to the hash.

func (*HashRing) Get

func (m *HashRing) Get(key string) string

Get gets the closest item in the hash to the provided key.

func (*HashRing) IsEmpty

func (m *HashRing) IsEmpty() bool

IsEmpty returns true if there are no items available.

Jump to

Keyboard shortcuts

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