selector

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Filter

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

Filter 过滤节点

type Next

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

Next 获取可用的节点

func Random

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

Random 随机选择节点

type Option

type Option func(*Options)

Option 根据配置选项初始化 selector

func OptRegistry added in v1.2.0

func OptRegistry(r registry.Registry) Option

OptRegistry 设置selector的注册表对象

func OptStrategy added in v1.2.0

func OptStrategy(fn Strategy) Option

OptStrategy 设置节点策略引擎

type Options

type Options struct {
	// 服务注册表
	Registry registry.Registry
	// 节点选择策略引擎
	Strategy Strategy
	// 扩展配置,可以添加自定义选项
	Context context.Context
}

Options selector的配置参数

type SelectOption

type SelectOption func(*SelectOptions)

SelectOption 调用select 方法的时候传入的配置

func OptWithFilter added in v1.2.0

func OptWithFilter(fn ...Filter) SelectOption

OptWithFilter 添加节点过滤规则

func OptWithStrategy added in v1.2.0

func OptWithStrategy(fn Strategy) SelectOption

OptWithStrategy 在调用select方法时候传入节点策略引擎

type SelectOptions

type SelectOptions struct {
	// 节点过滤器列表
	Filters []Filter
	// 节点选择策略引擎
	Strategy Strategy
	// 扩展配置,可以添加自定义选项
	Context context.Context
}

SelectOptions 节点选择器参数

type Selector

type Selector interface {
	Init(opts ...Option) error
	Options() Options
	Select(service string, opts ...SelectOption) (Next, error)
	Mark(service string, node *registry.Node, err error)
	Reset(service string)
	Close() error
	String() string
}

Selector 服务选择器接口

func NewSelector

func NewSelector(opts ...Option) Selector

NewSelector 创建选择器

type Strategy

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

Strategy 根据策略选择节点

Jump to

Keyboard shortcuts

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