Example #1
0
// NewHTTPPoolBasePath initializes an HTTP pool of peers just as NewHTTPPool,
// but uses a custom base path to accept requests on (the default is /_groupcache/).
// The basePath should look something like /mypath/.
// See the documentation on http.ServeMux for details on path consturciton
// (http://golang.org/pkg/net/http/#ServeMux).
// Note that you need to set this the same on all peers in the pool.
func NewHTTPPoolBasePath(self, basePath string) *HTTPPool {
	if httpPoolMade {
		panic("groupcache: NewHTTPPool must be called only once")
	}
	httpPoolMade = true
	p := &HTTPPool{basePath: basePath, self: self, peers: consistenthash.New(defaultReplicas, nil)}
	RegisterPeerPicker(func() PeerPicker { return p })
	http.Handle(basePath, p)
	return p
}
Example #2
0
// Set updates the pool's list of peers.
// Each peer value should be a valid base URL,
// for example "http://example.net:8000".
func (p *HTTPPool) Set(peers ...string) {
	p.mu.Lock()
	defer p.mu.Unlock()
	p.peers = consistenthash.New(defaultReplicas, nil)
	p.peers.Add(peers...)
}