2020-07-19 12:51:04 +03:00
|
|
|
// Package selector is for node selection and load balancing
|
2020-06-30 16:54:38 +03:00
|
|
|
package selector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/router"
|
2020-06-30 16:54:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultSelector is the default selector
|
|
|
|
DefaultSelector = NewSelector()
|
|
|
|
|
|
|
|
// ErrNoneAvailable is returned by select when no routes were provided to select from
|
|
|
|
ErrNoneAvailable = errors.New("none available")
|
|
|
|
)
|
|
|
|
|
|
|
|
// Selector selects a route from a pool
|
|
|
|
type Selector interface {
|
|
|
|
// Init a selector with options
|
|
|
|
Init(...Option) error
|
|
|
|
// Options the selector is using
|
|
|
|
Options() Options
|
|
|
|
// Select a route from the pool using the strategy
|
2020-07-02 18:09:48 +03:00
|
|
|
Select([]router.Route, ...SelectOption) (*router.Route, error)
|
2020-06-30 16:54:38 +03:00
|
|
|
// Record the error returned from a route to inform future selection
|
2020-06-30 17:51:26 +03:00
|
|
|
Record(router.Route, error) error
|
2020-06-30 16:54:38 +03:00
|
|
|
// Close the selector
|
|
|
|
Close() error
|
|
|
|
// String returns the name of the selector
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSelector creates new selector and returns it
|
|
|
|
func NewSelector(opts ...Option) Selector {
|
|
|
|
return newSelector(opts...)
|
|
|
|
}
|