lb

package module
v0.0.0-...-434fb5b Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2013 License: BSD-2-Clause Imports: 6 Imported by: 1

README

lb

lb is a general purpose load balancer, developed as an example for a Go workshop.

Documentation

Overview

Package lb contains an HTTP load balancer implementation.

It was developed for teaching purposes, prepared for a Go workshop at Globo.com.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadBalancer

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

LoadBalancer represents an HTTP load balancer. It implements a fair scheduling model, dispatching new requests to the backend with least load.

It implements http.Handler, so you can map a resource in a Go HTTP server to a load balancer.

Example

This example demonstrates the use of a LoadBalancer as an http.Handler.

package main

import (
	"github.com/fsouza/lb"
	"log"
	"net/http"
)

func main() {
	balancer, err := lb.NewLoadBalancer("localhost:8080", "localhost:8081", "localhost:8082")
	if err != nil {
		log.Fatal(err)
	}
	http.Handle("/", balancer)
	log.Fatal(http.ListenAndServe(":80", nil))
}
Output:

func NewLoadBalancer

func NewLoadBalancer(hosts ...string) (*LoadBalancer, error)

NewLoadBalancer returns a new instance of a LoadBalancer. It receives one or more hosts (represented by URLs), and balances the load between them.

func (*LoadBalancer) ServeHTTP

func (l *LoadBalancer) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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