Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
func (s ServiceAddresses) Equal(o ServiceAddresses) bool
Equal checks if the lists have the same addresses in them (regardless of sort order)