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)
Click to show internal directories.
Click to hide internal directories.