Version: v1.3.0 Latest Latest

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

Go to latest
Published: Feb 12, 2021 License: Apache-2.0 Imports: 6 Imported by: 0



Package sd defines some interfaces and implementations for service discovery



This section is empty.


View Source
var ErrNoHosts = errors.New("no hosts available")

ErrNoHosts is the error the balancer must return when there are 0 hosts ready


func RegisterSubscriberFactory

func RegisterSubscriberFactory(name string, sf SubscriberFactory) error

RegisterSubscriberFactory registers the received factory Deprecated: RegisterSubscriberFactory. Use the GetRegister function


type Balancer

type Balancer interface {
	Host() (string, error)

Balancer applies a balancing stategy in order to select the backend host to be used

func NewBalancer added in v1.1.0

func NewBalancer(subscriber Subscriber) Balancer

NewBalancer returns the best perfomant balancer depending on the number of available processors. If GOMAXPROCS = 1, it returns a round robin LB due there is no contention over the atomic counter. If GOMAXPROCS > 1, it returns a pseudo random LB optimized for scaling over the number of CPUs.

func NewRandomLB

func NewRandomLB(subscriber Subscriber) Balancer

NewRandomLB returns a new balancer using a fastrand pseudorandom generator

func NewRoundRobinLB

func NewRoundRobinLB(subscriber Subscriber) Balancer

NewRoundRobinLB returns a new balancer using a round robin strategy

type FixedSubscriber

type FixedSubscriber []string

FixedSubscriber has a constant set of backend hosts and they never get updated

func (FixedSubscriber) Hosts

func (s FixedSubscriber) Hosts() ([]string, error)

Hosts implements the subscriber interface

type Register

type Register struct {
	// contains filtered or unexported fields

Register is a SD register

func GetRegister

func GetRegister() *Register

GetRegister returns the package register

func (*Register) Get

func (r *Register) Get(name string) SubscriberFactory

Get implements the RegisterGetter interface

func (*Register) Register

func (r *Register) Register(name string, sf SubscriberFactory) error

Register implements the RegisterSetter interface

type Subscriber

type Subscriber interface {
	Hosts() ([]string, error)

Subscriber keeps the set of backend hosts up to date

func FixedSubscriberFactory

func FixedSubscriberFactory(cfg *config.Backend) Subscriber

FixedSubscriberFactory builds a FixedSubscriber with the received config

func GetSubscriber

func GetSubscriber(cfg *config.Backend) Subscriber

GetSubscriber returns a subscriber from package register Deprecated: GetSubscriber. Use the GetRegister function

type SubscriberFactory

type SubscriberFactory func(*config.Backend) Subscriber

SubscriberFactory builds subscribers with the received config

type SubscriberFunc

type SubscriberFunc func() ([]string, error)

SubscriberFunc type is an adapter to allow the use of ordinary functions as subscribers. If f is a function with the appropriate signature, SubscriberFunc(f) is a Subscriber that calls f.

func (SubscriberFunc) Hosts

func (f SubscriberFunc) Hosts() ([]string, error)

Hosts implements the Subscriber interface by executing the wrapped function


Path Synopsis
Package dnssrv defines some implementations for a dns based service discovery
Package dnssrv defines some implementations for a dns based service discovery

Jump to

Keyboard shortcuts

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