Documentation
¶
Index ¶
- Variables
- func Sort[C any](ctx context.Context, clients *Clients[C], sortValueFetch SortValueFetcher[C], ...) error
- func WithClients[C any, V any](clients *Clients[C], f func(context.Context, C) (v V, err error)) (v V, err error)
- func WithClientsContext[C any, V any](clients *Clients[C], ctx context.Context, ...) (v V, err error)
- type Clients
- type RollingStrategy
- type RollingStrategyAlwaysUseFirst
- type SortDirection
- type SortValueFetcher
- type StickyRollingStrategy
Constants ¶
This section is empty.
Variables ¶
var ErrorNoMoreClient = errors.New("no more clients")
Functions ¶
func Sort ¶ added in v1.6.8
func Sort[C any](ctx context.Context, clients *Clients[C], sortValueFetch SortValueFetcher[C], direction SortDirection) error
func WithClients ¶
Types ¶
type Clients ¶
type Clients[C any] struct { // contains filtered or unexported fields }
func NewClients ¶
func (*Clients[C]) Add ¶
func (c *Clients[C]) Add(client C)
Add appends a client to the pool, giving it the auto-generated provider name `client-<index>` where `<index>` is its position in the pool. Use Clients.AddNamed to give the client a meaningful name, which is then reported in errors and logs.
func (*Clients[C]) AddNamed ¶ added in v1.17.0
AddNamed appends a client to the pool under the provider name `name`, which is reported in errors and logs when this client is used and fails.
func (*Clients[C]) Names ¶ added in v1.17.0
Names returns the provider names of all clients in the pool, in pool order (which changes when the pool is sorted, see Clients.StartSorting).
func (*Clients[C]) Reset ¶ added in v1.17.0
func (c *Clients[C]) Reset()
Reset brings the rolling strategy back to the pool's declared order, so that the next call to WithClients/WithClientsContext starts again from the first client of the pool. It's the failback operation: a sticky strategy that rolled to a fallback provider after a transient error would otherwise stay on that fallback until the process restarts.
func (*Clients[C]) StartSorting ¶ added in v1.6.8
func (c *Clients[C]) StartSorting(ctx context.Context, direction SortDirection, sortValueFetcher SortValueFetcher[C], every time.Duration)
type RollingStrategy ¶ added in v1.6.8
type RollingStrategy[C any] interface { // contains filtered or unexported methods }
type RollingStrategyAlwaysUseFirst ¶ added in v1.6.8
type RollingStrategyAlwaysUseFirst[C any] struct { // contains filtered or unexported fields }
func NewRollingStrategyAlwaysUseFirst ¶ added in v1.6.8
func NewRollingStrategyAlwaysUseFirst[C any]() *RollingStrategyAlwaysUseFirst[C]
type SortDirection ¶ added in v1.6.8
type SortDirection int
const ( SortDirectionAscending SortDirection = iota SortDirectionDescending )
type SortValueFetcher ¶ added in v1.6.8
type StickyRollingStrategy ¶ added in v1.6.8
type StickyRollingStrategy[C any] struct { // contains filtered or unexported fields }
func NewStickyRollingStrategy ¶ added in v1.6.8
func NewStickyRollingStrategy[C any]() *StickyRollingStrategy[C]