lb

package
v0.0.0-...-2b27263 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: GPL-3.0 Imports: 6 Imported by: 8 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterStrategy

func RegisterStrategy(strategy StrategyType, factory StrategyFactory)

Types

type AddressResult

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

type Config

type Config struct {
	Dns      dns.Lookup
	Strategy StrategyType
}

func DefaultConfig

func DefaultConfig() (*Config, error)

type GenericLoadBalancer

type GenericLoadBalancer interface {
	Next(name string) (dns.Address, error)
}

Load balancer that can service request for any SRV record address

func NewGeneric

func NewGeneric(cfg *Config) GenericLoadBalancer
Example

Example of using a generic load balancer

srvName := "foo.service.fligl.io"
cfg, err := DefaultConfig()
if err != nil {
	panic(err)
}
lb := NewGeneric(cfg)

add1, err := lb.Next(srvName)
if err != nil {
	panic(err)
}
add2, err := lb.Next(srvName)
if err != nil {
	panic(err)
}

adds := []dns.Address{add1, add2}
sort.Sort(ByConnectionString(adds))

fmt.Printf("%s\n%s", adds[0], adds[1])
Output:
0.1.2.3:8001
4.5.6.7:8002

func NewRoundRobinStrategy

func NewRoundRobinStrategy(lib dns.Lookup) GenericLoadBalancer

type LoadBalancer

type LoadBalancer interface {
	Next() (dns.Address, error)
}

Load balancer that can service request for a configured SRV record address

func New

func New(cfg *Config, address string) LoadBalancer
Example

Example load balancer with defaults

cfg, err := DefaultConfig()
if err != nil {
	panic(err)
}
lb := New(cfg, "foo.service.fligl.io")

add1, err := lb.Next()
if err != nil {
	panic(err)
}
add2, err := lb.Next()
if err != nil {
	panic(err)
}

adds := []dns.Address{add1, add2}
sort.Sort(ByConnectionString(adds))

fmt.Printf("%s\n%s", adds[0], adds[1])
Output:
0.1.2.3:8001
4.5.6.7:8002

type ResultCache

type ResultCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCache

func NewCache() *ResultCache

func (*ResultCache) Next

func (s *ResultCache) Next(key string, srvs []net.SRV) (net.SRV, error)

type RoundRobinClb

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

func (*RoundRobinClb) Next

func (lb *RoundRobinClb) Next(name string) (dns.Address, error)

type SRVLoadBalancer

type SRVLoadBalancer struct {
	Lb      GenericLoadBalancer
	Address string
}

Default implementation for load balancing on a SRV record

func (*SRVLoadBalancer) Next

func (s *SRVLoadBalancer) Next() (dns.Address, error)

type StaticLoadBalancer

type StaticLoadBalancer struct {
	Address dns.Address
}

Specify an address to always return (good for compatibility and in test)

func (*StaticLoadBalancer) Next

func (s *StaticLoadBalancer) Next() (dns.Address, error)

type StrategyFactory

type StrategyFactory func(dns.Lookup) GenericLoadBalancer

type StrategyType

type StrategyType string
const RoundRobinStrategy StrategyType = "round-robin"

Jump to

Keyboard shortcuts

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