gsel

package
v0.0.0-...-c4191a4 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gsel provides selector definition and implements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetBuilder

func SetBuilder(builder Builder)

SetBuilder sets the default builder for globally used purpose.

Types

type Builder

type Builder interface {
	Name() string
	Build() Selector
}

Builder creates and returns selector in runtime.

func GetBuilder

func GetBuilder() Builder

GetBuilder returns the default builder for globally used purpose.

func NewBuilderLeastConnection

func NewBuilderLeastConnection() Builder

func NewBuilderRandom

func NewBuilderRandom() Builder

func NewBuilderRoundRobin

func NewBuilderRoundRobin() Builder

func NewBuilderWeight

func NewBuilderWeight() Builder

type DoneFunc

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

DoneFunc is callback function when RPC invoke done.

type DoneInfo

type DoneInfo struct {
	// Err is the rpc error the RPC finished with. It could be nil.
	Err error

	// Trailer contains the metadata from the RPC's trailer, if present.
	Trailer DoneInfoMD

	// BytesSent indicates if any bytes have been sent to the server.
	BytesSent bool

	// BytesReceived indicates if any byte has been received from the server.
	BytesReceived bool

	// ServerLoad is the load received from server. It's usually sent as part of
	// trailing metadata.
	//
	// The only supported type now is *orca_v1.LoadReport.
	ServerLoad interface{}
}

DoneInfo contains additional information for done.

type DoneInfoMD

type DoneInfoMD interface {
	// Len returns the number of items in md.
	Len() int

	// Get obtains the values for a given key.
	//
	// k is converted to lowercase before searching in md.
	Get(k string) []string

	// Set sets the value of a given key with a slice of values.
	//
	// k is converted to lowercase before storing in md.
	Set(key string, values ...string)

	// Append adds the values to key k, not overwriting what was already stored at
	// that key.
	//
	// k is converted to lowercase before storing in md.
	Append(k string, values ...string)

	// Delete removes the values for a given key k which is converted to lowercase
	// before removing it from md.
	Delete(k string)
}

DoneInfoMD is a mapping from metadata keys to value array. Users should use the following two convenience functions New and Pairs to generate MD.

type Node

type Node interface {
	Service() gsvc.Service
	Address() string
}

Node is node interface.

type Nodes

type Nodes []Node

Nodes contains multiple Node.

func (Nodes) String

func (ns Nodes) String() string

String formats and returns Nodes as string.

type Selector

type Selector interface {
	// Pick selects and returns service.
	Pick(ctx context.Context) (node Node, done DoneFunc, err error)

	// Update updates services into Selector.
	Update(ctx context.Context, nodes Nodes) error
}

Selector for service balancer.

func NewSelectorLeastConnection

func NewSelectorLeastConnection() Selector

func NewSelectorRandom

func NewSelectorRandom() Selector

func NewSelectorRoundRobin

func NewSelectorRoundRobin() Selector

func NewSelectorWeight

func NewSelectorWeight() Selector

Jump to

Keyboard shortcuts

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