selector

package
v1.0.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package selector is a way to pick a list of service nodes

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrNoneAvailable = errors.New("none available")
)

Functions

This section is empty.

Types

type Filter

type Filter func([]*registry.Service) []*registry.Service

Filter is used to filter a service during the selection process

func FilterEndpoint

func FilterEndpoint(name string) Filter

FilterEndpoint is an endpoint based Next Filter which will only return services with the endpoint specified.

func FilterLabel

func FilterLabel(key, val string) Filter

FilterLabel is a label based Next Filter which will only return services with the label specified.

func FilterVersion

func FilterVersion(version string) Filter

FilterVersion is a version based Next Filter which will only return services with the version specified.

type Option

type Option func(*Options)

Option used to initialise the selector

func Name

func Name(n string) Option

func Registry

func Registry(r registry.Registry) Option

Registry sets the registry used by the selector

func SetStrategy

func SetStrategy(fn Strategy) Option

SetStrategy sets the default strategy for the selector

type Options

type Options struct {
	Name     string
	Registry registry.Registry
	Strategy Strategy

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type SelectOption

type SelectOption func(*SelectOptions)

SelectOption used when making a select call

func WithFilter

func WithFilter(fn ...Filter) SelectOption

WithFilter adds a filter function to the list of filters used during the Next call.

func WithStrategy

func WithStrategy(fn Strategy) SelectOption

Strategy sets the selector strategy

type SelectOptions

type SelectOptions struct {
	Filters  []Filter
	Strategy Strategy

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Selector

type Selector interface {
	Init(opts ...Option) error
	Options() Options
	// Next returns the next node
	Next(service string, opts ...SelectOption) (*registry.Node, error)
	// Mark sets the success/error against a node
	Mark(service string, node *registry.Node, err error)
	// Reset returns state back to zero for a service
	Reset(service string)
	// Close renders the selector unusable
	Close() error
	// Name of the selector
	String() string
}

Selector builds on the registry as a mechanism to pick nodes and mark their status. This allows host pools and other things to be built using various algorithms.

type Strategy

type Strategy func([]*registry.Service) (*registry.Node, error)

Strategy is a selection strategy e.g random, round robin

func Random

func Random() Strategy

Random is a random strategy algorithm for node selection

func RoundRobin

func RoundRobin() Strategy

RoundRobin is a round robin strategy algorithm for node selection

Directories

Path Synopsis
Package dns provides a dns SRV selector
Package dns provides a dns SRV selector
Package static provides a static resolver which returns the name/ip passed in without any change
Package static provides a static resolver which returns the name/ip passed in without any change

Jump to

Keyboard shortcuts

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