Documentation ¶
Overview ¶
This package allows you to iterate over a set of service nodes, either in sequence or randomly. The RNG can be seeded and will give the same node order for the same seed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BalanceStrat ¶
type BalanceStrat int
What kind of strategy should be used to iterate the nodes. Sequencial simply walks from the first downwards, ignoring cost. Random first picks a random node based on cost, with random fallback. Hash works like random, but seeds the RNG with the seed given, thus generating the same sequence for the same seed.
const ( StratSeq BalanceStrat = iota StratRandom StratHash )
type ConnStatus ¶
type ConnStatus int
The reason you're calling Connection.Next. Start for the first call or when you want to move to the next node even when the current was used successfully. Fail if there was a hard failure, e.g. connection refused. SoftFail if there was a soft failure, e.g. 503 Service Unavailable.
const ( Start ConnStatus = iota Fail SoftFail )
type Connection ¶
type Connection interface { Next(status ConnStatus) interface{} Close() error }
An iterator for the service nodes. Each call to Next returns a new node you should connect to. Once a node has been used successfully, call Close to finish.
Next will return nil when the nodes are exhausted, based on the number of nodes and the Service.Retries count.
type Service ¶
type Service struct { Retries int // How many times to retry the whole set of nodes. FailCost int // Overrides normal node cost on hard failures (connection refused etc.) SoftFailCost int // Overrides normal node cost on soft failures (503 Service unavailable) Strat BalanceStrat // contains filtered or unexported fields }
A service with a set of nodes. Initialize with the Strat you will use and call Service.AddNode to add nodes.
func (*Service) AddNode ¶
Add a node to the service. This function is not thread safe and can't be used while you're connecting to the nodes.
func (*Service) GetCosts ¶
Return the default and effective (current) costs for the given node at idx.
func (*Service) NewConn ¶
func (sb *Service) NewConn(seed []byte) Connection
Setup a service connection, possibly seeding the random order generator with the given seed.