selector

package
v0.0.0-...-01d4da0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MulanPSL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAvailable = errors.ServiceUnavailable("no_available_node", "")

Functions

func NewPeerContext

func NewPeerContext(ctx context.Context, p *Peer) context.Context

func SetGlobalSelector

func SetGlobalSelector(builder Builder)

Types

type Builder

type Builder interface {
	Build() Selector
}

func GlobalSelector

func GlobalSelector() Builder

type DefaultNode

type DefaultNode struct {
	// contains filtered or unexported fields
}

func (*DefaultNode) Address

func (n *DefaultNode) Address() string

func (*DefaultNode) InitialWeight

func (n *DefaultNode) InitialWeight() *int64

func (*DefaultNode) Metadata

func (n *DefaultNode) Metadata() map[string]string

func (*DefaultNode) Scheme

func (n *DefaultNode) Scheme() string

func (*DefaultNode) ServiceName

func (n *DefaultNode) ServiceName() string

func (*DefaultNode) Version

func (n *DefaultNode) Version() string

type DoneFunc

type DoneFunc func(ctx context.Context, di DoneInfo)

type DoneInfo

type DoneInfo struct {
	Err     error
	ReplyMD ReplyMD
	// BytesSent indicates if any bytes have been sent to the server.
	BytesSend bool
	// BytesReceived indicates if any byte has been received from the server.
	BytesReceived bool
}

type Node

type Node interface {
	Scheme() string
	Address() string
	ServiceName() string

	InitialWeight() *int64
	Version() string
	Metadata() map[string]string
}

func NewNode

func NewNode(scheme, addr string, ins *registry.ServiceInstance) Node

type NodeFilter

type NodeFilter func(context.Context, []Node) []Node

type Peer

type Peer struct {
	Node Node
}

func FromPeerContext

func FromPeerContext(ctx context.Context) (p *Peer, ok bool)

type Rebalancer

type Rebalancer interface {
	Apply(nodes []Node)
}

type ReplyMD

type ReplyMD interface {
	Get(key string) string
}

type SelectOption

type SelectOption func(options *SelectOptions)

func WithNodeFilter

func WithNodeFilter(fn ...NodeFilter) SelectOption

type SelectOptions

type SelectOptions struct {
	NodeFilters []NodeFilter
}

type Selector

type Selector interface {
	Rebalancer
	Select(ctx context.Context, opts ...SelectOption) (selected Node, done DoneFunc, err error)
}

Jump to

Keyboard shortcuts

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