lbsql

package module
v0.0.0-...-7169aca Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 4 Imported by: 0

README

go-lbsql

Go library for doing client side load balancing.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConnectors = errors.New("lbsql: no available connectors")

ErrNoConnectors is returned when there are no connectors added to the balancer.

Functions

This section is empty.

Types

type Balancer

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

Balancer is a driver.Connector that randomly picks between the connectors that have been added to it when establishing connections.

func NewBalancer

func NewBalancer() *Balancer

NewBalancer returns a Balancer.

func (*Balancer) Add

func (b *Balancer) Add(name string, c driver.Connector)

Add adds a driver.Connector to the balancer.

func (*Balancer) Connect

func (b *Balancer) Connect(ctx context.Context) (driver.Conn, error)

Connect connects to a random driver.Connector. If the connection fails it retries all the available connectors until one succeeds, or the context is canceled.

func (*Balancer) ConnectorNames

func (b *Balancer) ConnectorNames() []string

ConnectorNames returns a list of all the names of connectors currently in the balancer.

func (*Balancer) Driver

func (b *Balancer) Driver() driver.Driver

Driver returns the balancer.

func (*Balancer) Open

func (b *Balancer) Open(_ string) (driver.Conn, error)

Open is a thin wrapper around Connect.

func (*Balancer) OpenConnector

func (b *Balancer) OpenConnector(name string) (driver.Connector, error)

OpenConnector returns the balancer.

func (*Balancer) Remove

func (b *Balancer) Remove(name string)

Remove removes a connector from the balancer.

Jump to

Keyboard shortcuts

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