go-micro: github.com/micro/go-micro/selector Index | Files | Directories

package selector

import "github.com/micro/go-micro/selector"

Package selector is a way to load balance service nodes

Index

Package Files

default.go filter.go options.go selector.go strategy.go

Variables

var (
    DefaultSelector = newDefaultSelector()

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

type Filter Uses

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

Filter is used to filter a service during the selection process

func FilterEndpoint Uses

func FilterEndpoint(name string) Filter

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

func FilterLabel Uses

func FilterLabel(key, val string) Filter

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

func FilterVersion Uses

func FilterVersion(version string) Filter

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

type Next Uses

type Next func() (*registry.Node, error)

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

func Random Uses

func Random(services []*registry.Service) Next

Random is a random strategy algorithm for node selection

func RoundRobin Uses

func RoundRobin(services []*registry.Service) Next

RoundRobin is a roundrobin strategy algorithm for node selection

type Option Uses

type Option func(*Options)

Option used to initialise the selector

func Registry Uses

func Registry(r registry.Registry) Option

Registry sets the registry used by the selector

func SetStrategy Uses

func SetStrategy(fn Strategy) Option

SetStrategy sets the default strategy for the selector

type Options Uses

type Options struct {
    Registry registry.Registry
    Strategy Strategy

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

type SelectOption Uses

type SelectOption func(*SelectOptions)

SelectOption used when making a select call

func WithFilter Uses

func WithFilter(fn ...Filter) SelectOption

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

func WithStrategy Uses

func WithStrategy(fn Strategy) SelectOption

Strategy sets the selector strategy

type SelectOptions Uses

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 Uses

type Selector interface {
    Init(opts ...Option) error
    Options() Options
    // Select returns a function which should return the next node
    Select(service string, opts ...SelectOption) (Next, 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.

func NewSelector Uses

func NewSelector(opts ...Option) Selector

type Strategy Uses

type Strategy func([]*registry.Service) Next

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

Directories

PathSynopsis
cachePackage cache is a caching selector.

Package selector imports 6 packages (graph) and is imported by 127 packages. Updated 2018-11-13. Refresh now. Tools for package owners.