Documentation ¶
Overview ¶
Package rpc implements a reference PeerLoader and corresponding handler.
Index ¶
- func Handler(cache *ttlcache.Cache, prefix string, timeout time.Duration) http.Handler
- func Loader(cache string, client *http.Client, basePath string) ttlcache.PeerLoader
- func UninstrumentedHandler(cache *ttlcache.Cache, prefix string, timeout time.Duration) http.Handler
- type Delegate
- type Metadata
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns a http.Handler to respond to requests sent by the PeerLoader returned by Loader(). We expect requests with a path beginning with prefix, which should match the first argument to http.Handle(), e.g. "/". Note it must end with a trailing slash in order to do a prefix rather than exact match. The timeout is to prevent gets endlessly bouncing around a cluster, even if the client is willing to wait.
func Loader ¶
Loader returns a new PeerLoader that will send requests to <addr>:<metaport><basePath>/keys/<key> using the provided client. As we modify the client's transport, it should not be used for any other purpose, as the requests will lead to incorrect metrics. The timeout of each request is controlled by the client's Timeout. The loader implementation will back-off exponentially until the context expires. If non-empty, the base path must begin with a /.
func UninstrumentedHandler ¶
func UninstrumentedHandler(cache *ttlcache.Cache, prefix string, timeout time.Duration) http.Handler
UninstrumentedHandler provides the underlying handler used by Handler, without instrumentation. This is intended to be a useful starting point for an external request handler.
Types ¶
type Delegate ¶
type Delegate struct {
// contains filtered or unexported fields
}
Delegate is a trivial memberlist.Delegate implementation that responds with a static set of metadata. This struct is immutable.
func NewDelegate ¶
NewDelegate returns a delegate that will serve metadata identifying the provided port.
func (Delegate) GetBroadcasts ¶
func (Delegate) LocalState ¶
func (Delegate) MergeRemoteState ¶
type Metadata ¶
type Metadata struct { // Port is the port the node is listening for peer loads on. Port uint16 }
Metadata contains additional information about a given peer, and is required for other peers to be able to interact with it. Direct use of this struct is only necessary if already using memberlist's metadata facility elsewhere, and you want to embed this package's metadata in your own. Otherwise, simply use NewDelegate() passing in the port directly.
type Pair ¶
type Pair struct { // Prefix is the pattern under which the loader and handler will operate, // e.g. /ttlcache/caches/<name>/keys/. This is passed unmodified when // binding the handler, so must end with a /. The loader and handler are // deliberately not cache-aware to allow registering different handlers // against different caches. Prefix string }
Pair is a wrapper around Loader and Handler that makes it impossible to have an inconsistent base path. Fields should not be modified post-creation.