discovery

package module
v0.0.0-...-8585d9b Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: MIT Imports: 13 Imported by: 0

README

discovery

Instead of creating a client that is specific to any given service-discovery system, discovery is a client for managing DNS resolution.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default discovery config
	DefaultConfig = DiscoveryConfig{
		ResolvConf:             "/etc/resolv.conf",
		ResolutionPriority:     []ResolutionType{SRV, AAAA, A},
		MinRetryInterval:       time.Second,
		SubscribeRetryInterval: time.Second,
	}
)

Functions

This section is empty.

Types

type Callback

type Callback func(context.Context, ServiceAddresses) error

Callback is a function which will be called with updated ServiceAddresses

type Discovery

type Discovery interface {
	// GetServiceAddresses will do the lookup and return the list in-order from DNS
	GetServiceAddresses(context.Context, string) (ServiceAddresses, error)
	// SubscribeServiceAddresses will do the lookup and give the results to Callback
	SubscribeServiceAddresses(context.Context, string, Callback) error
}

Discovery defines the interface for this package; this way if there are additional implementation in the future the interface will remain the same

func NewDiscovery

func NewDiscovery(c DiscoveryConfig) (Discovery, error)

NewDiscovery returns a new discovery client based on the given config

func NewDiscoveryFromEnv

func NewDiscoveryFromEnv() (Discovery, error)

NewDiscoveryFromEnv is a convenience method for creating a client from environment config

type DiscoveryConfig

type DiscoveryConfig struct {
	// ResolvConf is the path to resolv.conf
	ResolvConf             string
	ResolutionPriority     []ResolutionType
	MinRetryInterval       time.Duration
	SubscribeRetryInterval time.Duration
}

DiscoveryConfig is the config for the discovery client

func ConfigFromEnv

func ConfigFromEnv() (*DiscoveryConfig, error)

type ResolutionType

type ResolutionType int

ResolutionType is a DNS query type (SRV, A, AAAA)

const (
	SRV ResolutionType = iota
	AAAA
	A
)

type ServiceAddress

type ServiceAddress struct {
	Name     string
	IP       net.IP
	Port     uint16
	Priority uint16
	Weight   uint16
	// contains filtered or unexported fields
}

ServiceAddress is a struct which contains the SD information about a given target

func (ServiceAddress) Equal

func (s ServiceAddress) Equal(o ServiceAddress) bool

Equal returns whether this address matches another one

func (ServiceAddress) IsExpired

func (s ServiceAddress) IsExpired() bool

IsExpired returns whether the ServiceAddress is stale. Note: if this was statically defined (hard-coded IP in the query) it will never expire

type ServiceAddresses

type ServiceAddresses []ServiceAddress

ServiceAddresses is a list of the information about targets, for the same service name

func ShuffleServiceAddresses

func ShuffleServiceAddresses(arr ServiceAddresses) ServiceAddresses

ShuffleServiceAddresses will randomize ServiceAddresses

func (ServiceAddresses) Equal

Equal checks if the lists have the same addresses in them (regardless of sort order)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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