crr

package
v0.0.0-...-c570f4e Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildEndpointKey

func BuildEndpointKey(params map[string]*string) string

BuildEndpointKey will sort the keys in alphabetical order and then retrieve the values in that order. Those values are then concatenated together to form the endpoint key.

Types

type Discoverer

type Discoverer interface {
	Discover() (Endpoint, error)
}

Discoverer is an interface used to discovery which endpoint hit. This allows for specifics about what parameters need to be used to be contained in the Discoverer implementor.

type Endpoint

type Endpoint struct {
	Key       string
	Addresses WeightedAddresses
}

Endpoint represents an endpoint used in endpoint discovery.

func (*Endpoint) Add

func (e *Endpoint) Add(addr WeightedAddress)

Add will add a given WeightedAddress to the address list of Endpoint.

func (*Endpoint) GetValidAddress

func (e *Endpoint) GetValidAddress() (WeightedAddress, bool)

GetValidAddress will return a non-expired weight endpoint

func (*Endpoint) Len

func (e *Endpoint) Len() int

Len returns the number of valid endpoints where valid means the endpoint has not expired.

func (*Endpoint) Prune

func (e *Endpoint) Prune() bool

Prune will prune the expired addresses from the endpoint by allocating a new []WeightAddress. This is not concurrent safe, and should be called from a single owning thread.

type EndpointCache

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

EndpointCache is an LRU cache that holds a series of endpoints based on some key. The datastructure makes use of a read write mutex to enable asynchronous use.

func NewEndpointCache

func NewEndpointCache(endpointLimit int64) *EndpointCache

NewEndpointCache will return a newly initialized cache with a limit of endpointLimit entries.

func (*EndpointCache) Add

func (c *EndpointCache) Add(endpoint Endpoint)

Add is a concurrent safe operation that will allow new endpoints to be added to the cache. If the cache is full, the number of endpoints equal endpointLimit, then this will remove the oldest entry before adding the new endpoint.

func (*EndpointCache) Get

func (c *EndpointCache) Get(d Discoverer, endpointKey string, required bool) (WeightedAddress, error)

Get will retrieve a weighted address based off of the endpoint key. If an endpoint should be retrieved, due to not existing or the current endpoint has expired the Discoverer object that was passed in will attempt to discover a new endpoint and add that to the cache.

func (*EndpointCache) Has

func (c *EndpointCache) Has(endpointKey string) bool

Has returns if the enpoint cache contains a valid entry for the endpoint key provided.

type WeightedAddress

type WeightedAddress struct {
	URL     *url.URL
	Expired time.Time
}

WeightedAddress represents an address with a given weight.

func (WeightedAddress) HasExpired

func (e WeightedAddress) HasExpired() bool

HasExpired will return whether or not the endpoint has expired with the exception of a zero expiry meaning does not expire.

type WeightedAddresses

type WeightedAddresses []WeightedAddress

WeightedAddresses represents a list of WeightedAddress.

Jump to

Keyboard shortcuts

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