selector

package
v0.0.0-...-a0c90f5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScoreNodes

func ScoreNodes(keys []string, services []*micro.Service) (possibleNodes []*micro.Node, scores []uint64)

ScoreNodes returns a score for each node found in the given services.

Types

type Filter

type Filter func([]*micro.Service) ([]*micro.Service, error)

Filter is used to filter a service during the selection process.

type Next

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

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

func Random

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

func RoundRobin

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

RoundRobin is a roundrobin strategy algorithm for node selection

type Option

type Option func(*Options)

func WithCacheSeconds

func WithCacheSeconds(seconds int32) Option

WithCacheSeconds sets the seconds of cache ttl

func WithRegistry

func WithRegistry(r micro.Registry) Option

WithRegistry sets the registry used by the selector.

func WithStrategy

func WithStrategy(fn Strategy) Option

WithStrategy sets the default strategy for the selector.

type Options

type Options struct {
	Registry micro.Registry
	Strategy Strategy
	TTL      time.Duration
}

type Selector

type Selector interface {
	// Select returns a function which should return the next node
	Select(service string, filters ...Filter) (Next, error)
	// Mark sets the success/error against a node
	Mark(service string, node *micro.Node, err error)
	// Reset returns state back to zero for a service
	Reset(service string)
	// Close renders the selector unusable
	Close() error

	Name() string
}

func NewSelector

func NewSelector(opts ...Option) (Selector, error)

type Strategy

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

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

func NewSharedStrategy

func NewSharedStrategy(keys []string) Strategy

NewSharedStrategy returns a `SelectOption` that directs all request according to the given `keys`.

Jump to

Keyboard shortcuts

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