selector

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("not found")
	ErrNoneAvailable         = errors.New("none available")
	ErrRunOutAllServiceNodes = errors.New("has used out all provider nodes")
)

Functions

This section is empty.

Types

type Mode added in v0.2.0

type Mode int

Mode defines the algorithm of selecting a provider from cluster

const (
	SM_BEGIN Mode = iota
	SM_Random
	SM_RoundRobin
	SM_END
)

func (Mode) String added in v0.2.0

func (s Mode) String() string

type ModeFunc added in v0.2.0

type ModeFunc func([]*registry.ServiceURL) Next

func SelectorNext

func SelectorNext(mode Mode) ModeFunc

type NewSelector added in v0.2.0

type NewSelector func(...Option) Selector

type Next

type Next func(ID int64) (*registry.ServiceURL, error)

Next is a function that returns the next node based on the selector's strategy

type Option

type Option func(*Options)

Option used to initialise the selector

func Context

func Context(ctx context.Context) Option

func Registry

func Registry(r registry.Registry) Option

Registry sets the registry used by the selector

func SelectMode

func SelectMode(mode Mode) Option

SetStrategy sets the default strategy for the selector

type Options

type Options struct {
	Registry registry.Registry
	Mode     Mode // selector mode

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

type Selector

type Selector interface {
	Options() Options
	// Select returns a function which should return the next node
	Select(conf registry.ServiceConfigIf) (Next, error)
	// Close renders the selector unusable
	Close() error
	// Name of the selector
	String() string
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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