hashring

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hashring implements a loadbalance.Selector that selects hosts using groupcache's consistenthash package.

Populate the correct request header before making the request because the value of the header is used as the key when choosing a host. Not setting the header will result in a malformed URL.

req, _ := http.NewRequest("GET", "http://host/foo/bar", nil)
req.Header.Set(hashring.Header, "bar")
client.Do(req)

See: https://godoc.org/github.com/golang/groupcache/consistenthash

Index

Constants

This section is empty.

Variables

View Source
var (
	// Header defines the HTTP header to use for the request's key.
	// The ring is searched using a hash of the key.
	Header = "HashRing-Key"

	// Hash is the default function used to hash hosts and keys.
	Hash = crc32.ChecksumIEEE // func([]byte) uint32

	// Replicas defines the number of replica hosts created when
	// populating the ring.
	Replicas = 50
)

Functions

func SelectFrom

func SelectFrom(hosts ...string) loadbalance.Selector

SelectFrom returns a Selector that selects hosts using a hash ring.

Types

This section is empty.

Jump to

Keyboard shortcuts

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