fireload

package module
v0.0.0-...-c103d31 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2015 License: MIT Imports: 3 Imported by: 0

README

fireload


Build Status Coverage Status

A load balancer for multiple Firebase instances.

Installation

go get -u github.com/CloudCom/fireload

Usage

Import fireload

import "github.com/CloudCom/fireload"
Namespaces

Creating a namespace:

instance1 := fireload.NewNamespace(“https://foo.firebaseIO.com”)
instance2 := fireload.NewNamespace(“https://bar.firebaseIO.com”)

You can also set/get Metadata on namespaces:

instance1.Metadata.Set(“awesome”, true)
instance1.Metadata.Set("secret", "very very secret")

instance2.Metadata.Set(“secret”, “my-awesome-secret”)

if secret, ok := instance2.Metdata.Get("awesome"); !ok {
  println("instance2 is not awesome")
}
Pool

Creating a pool:

pool, err := fireload.NewPool(instance1, instance2)
if err != nil {
  log.Fatal(err)
}

Pools allow you to specify the selection strategy used when retrieving a Namespace.

  • Random (default)
  • RoundRobin
pool.SetStrategy(fireload.StrategyRoundRobin)

Getting a namespace and using it:

namespace := pool.Next()
f := firego.New(namespace.Domain)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidStrategy = errors.New("Invalid strategy")

ErrInvalidStrategy is returned by `Pool.SetStrategy` when the given strategy is invalid.

Functions

This section is empty.

Types

type Metadata

type Metadata map[string]interface{}

Metadata represents key-value pairs of metadata associated with a Namespace

func (Metadata) Get

func (m Metadata) Get(key string) (interface{}, bool)

Get retrieves the value stored under key.

func (Metadata) Set

func (m Metadata) Set(key string, value interface{})

Set adds the given key-value pair

type Namespace

type Namespace struct {
	// Domain is the fully-qualified domain name of the Firebase Namespace.
	// The Domain for the samplechat Namespace mentioned in the Firebase documentation
	// would be `samplechat.firebaseio-demo.com`.
	Domain string

	// Metadata holds any key-value pairs associated with this Namespace; e.g. the admin secret.
	Metadata Metadata
}

Namespace represents a Firebase Namespace (e.g. `<namespace>.firebaseio.com`).

func NewNamespace

func NewNamespace(domain string) Namespace

NewNamespace returns a Namespace with the given domain.

func (Namespace) String

func (n Namespace) String() string

String satisfies the fmt.Stringer interface and returns the Namespace's Domain.

type Pool

type Pool struct {
	Nodes *ring.Ring
	Strategy
}

Pool represents a pool of Firebase Namespaces, with an associated Strategy for load balancing in the pool.

func NewPool

func NewPool(nodes ...Namespace) (*Pool, error)

NewPool returns a Pool with the given namespaces.

func (*Pool) Add

func (p *Pool) Add(ns Namespace)

Add inserts the given namespace into the pool.

The Nodes in a Pool are considered to be unordered, so the Namespace is inserted at the "next" position (i.e. a subsequent call to NextRoundRobin would return the inserted Namespace).

func (*Pool) Drop

func (p *Pool) Drop(domain string) error

Drop removes all Namespaces with the given domain from the pool.

func (*Pool) Next

func (p *Pool) Next() Namespace

Next returns from the pool the Namespace deemed to be "next" according to the pool's strategy.

func (*Pool) NextRandom

func (p *Pool) NextRandom() Namespace

NextRandom returns a random Namespace from the pool

func (*Pool) NextRoundRobin

func (p *Pool) NextRoundRobin() Namespace

NextRoundRobin returns a Namespace in "round-robin" fashion

func (*Pool) SetStrategy

func (p *Pool) SetStrategy(strategy Strategy) error

SetStrategy sets the strategy of the pool to the given strategy.

type Strategy

type Strategy int

Strategy represents various strategies for load balancing a pool of Firebase Namespaces

const (
	// StrategyRandom picks a Namespace at random
	StrategyRandom Strategy = iota

	// StrategyRoundRobin returns Namespaces in "round-robin" fashion
	StrategyRoundRobin
)

Jump to

Keyboard shortcuts

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