gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/client/selector/selector.go (about) 1 // Package selector is a way to pick a list of service nodes 2 package selector 3 4 import ( 5 "errors" 6 7 "gitee.com/liuxuezhan/go-micro-v1.18.0/registry" 8 ) 9 10 // Selector builds on the registry as a mechanism to pick nodes 11 // and mark their status. This allows host pools and other things 12 // to be built using various algorithms. 13 type Selector interface { 14 Init(opts ...Option) error 15 Options() Options 16 // Select returns a function which should return the next node 17 Select(service string, opts ...SelectOption) (Next, error) 18 // Mark sets the success/error against a node 19 Mark(service string, node *registry.Node, err error) 20 // Reset returns state back to zero for a service 21 Reset(service string) 22 // Close renders the selector unusable 23 Close() error 24 // Name of the selector 25 String() string 26 } 27 28 // Next is a function that returns the next node 29 // based on the selector's strategy 30 type Next func() (*registry.Node, error) 31 32 // Filter is used to filter a service during the selection process 33 type Filter func([]*registry.Service) []*registry.Service 34 35 // Strategy is a selection strategy e.g random, round robin 36 type Strategy func([]*registry.Service) Next 37 38 var ( 39 DefaultSelector = NewSelector() 40 41 ErrNotFound = errors.New("not found") 42 ErrNoneAvailable = errors.New("none available") 43 )