balancer

package
v0.0.0-...-bd3f6cd Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const EndpointPort = 9923

Port is the port to listen for updates to endpoints. TODO make dynamic

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer struct {
	Port      int
	Endpoints Endpoints
	Policy    Policy
	sync.RWMutex
}

Balancer is a load balancer.

func New

func New(port int, endpoints Endpoints, policy string) *Balancer

New creates a new Balancer.

func (*Balancer) ListenForEndpoints

func (b *Balancer) ListenForEndpoints(port int)

ListenForEndpoints listens for updates endpoints.

func (*Balancer) Select

func (b *Balancer) Select(e Endpoints) Endpoint

Select selects an endpoint using the current scheduling policy.

func (*Balancer) Start

func (b *Balancer) Start(stop chan struct{}) error

Start starts b. This function blocks if start is successful.

type Endpoint

type Endpoint struct {
	Id   string
	Ip   string
	Port int
}

Endpoint is a port forwarding endpoint.

func ParseEndpoint

func ParseEndpoint(addr string) Endpoint

ParseEndpoint creates a new Endpoint from addr.

func (Endpoint) Addr

func (ep Endpoint) Addr() string

Addr returns the address of the endpoint in the format ip:port.

func (Endpoint) String

func (ep Endpoint) String() string

String returns string representation of the endpoint.

type Endpoints

type Endpoints []Endpoint

Endpoints is a list of Endpoint.

func (*Endpoints) Add

func (e *Endpoints) Add(ep Endpoint)

Add adds ep to the list of endpoints.

func (Endpoints) Addrs

func (e Endpoints) Addrs() []string

Addrs returns the list of Addr of all endpoints in the list.

func (*Endpoints) Delete

func (e *Endpoints) Delete(id string)

Delete deletes endpoint with id from the list of endpoints.

func (Endpoints) Len

func (e Endpoints) Len() int

Len is the length of the list.

type Message

type Message struct {
	Endpoint Endpoint
	Remove   bool
}

Message is body for an endpoint update.

type Policy

type Policy interface {
	Select(e Endpoints) Endpoint
}

Policy is a selection policy.

type Random

type Random struct{}

Random is a random policy.

func (Random) Select

func (r Random) Select(e Endpoints) Endpoint

Select satisfies Policy.

type RoundRobin

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

RoundRobin is a round robin policy.

func (*RoundRobin) Select

func (r *RoundRobin) Select(e Endpoints) Endpoint

Select satisfies Policy.

Jump to

Keyboard shortcuts

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