endpoint

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package endpoint provides some auxiliary functions about endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetWeight

func GetWeight(ep loadbalancer.Endpoint) int

GetWeight returns the weight of the endpoint if it has implements the interface Weighter. Or, check whether it has implemented the interface Unwrapper and unwrap it. If still failing, return 1 instead.

func Sort added in v0.8.0

func Sort(eps loadbalancer.Endpoints)

SortEndpoints sorts the endpoints by the ASC order.

Types

type Endpoint

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

Endpoint is a common endpoint implementation.

func New added in v0.8.0

func New(id string, serve loadbalancer.ServeFunc) *Endpoint

New returns a new common endpoint with the id and serve function.

If serve is nil, use a no-op function instead.

func (*Endpoint) Concurrent added in v0.8.0

func (e *Endpoint) Concurrent() int

Concurrent returns the number that the endpoint is serving the requests concurrently.

NOTICE: it's thread-safe.

func (*Endpoint) Config added in v0.8.0

func (e *Endpoint) Config() any

Config returns the configuration information of the endpoint.

NOTICE: it's thread-safe.

func (*Endpoint) ID

func (e *Endpoint) ID() string

Serve returns the endpoint id, which implements the interface loadbalancer.Endpoint#ID.

func (*Endpoint) Serve

func (e *Endpoint) Serve(c context.Context, r any) (any, error)

Serve serves the request, which implements the interface loadbalancer.Endpoint#Serve.

func (*Endpoint) ServeFunc added in v0.8.0

func (e *Endpoint) ServeFunc() loadbalancer.ServeFunc

ServeFunc returns the serve function.

func (*Endpoint) SetConfig added in v0.8.0

func (e *Endpoint) SetConfig(c any)

SetConfig sets the configuration information of the endpoint.

NOTICE: it's thread-safe.

func (*Endpoint) SetServeFunc added in v0.8.0

func (e *Endpoint) SetServeFunc(serve loadbalancer.ServeFunc)

SetServeFunc resets the serve function of the endpoint.

func (*Endpoint) SetWeight added in v0.8.0

func (e *Endpoint) SetWeight(weight int)

SetWeight resets the weight of the endpoint, which is thread-safe.

NOTICE: weight must be equal to or greater than 0. If 0, use 1 instead.

func (*Endpoint) String added in v0.8.0

func (e *Endpoint) String() string

String returns the description of the endpoint, which is equal to ID.

func (*Endpoint) Total added in v0.8.0

func (e *Endpoint) Total() int

Total returns the total number that the endpoint has served the requests.

NOTICE: it's thread-safe.

func (*Endpoint) Update

func (e *Endpoint) Update(src loadbalancer.Endpoint) bool

Update tries to update itself to src.

func (*Endpoint) Weight added in v0.8.0

func (e *Endpoint) Weight() int

Weight returns the weight of the endpoint, which implements the interface Weighter.

NOTICE: it's thread-safe.

type Unwrapper added in v0.8.0

type Unwrapper interface {
	Unwrap() loadbalancer.Endpoint
}

Unwrapper is used to unwrap the inner endpoint.

type Updater added in v0.8.0

type Updater interface {
	Update(src loadbalancer.Endpoint) (success bool)
}

Updater is used to try to update the endpoint from another src.

type Weighter added in v0.8.0

type Weighter interface {
	// Weight returns the weight of the endpoint, which must be a positive integer.
	//
	// The bigger the value, the higher the weight.
	Weight() int
}

Weighter is used to get the weight of an endpoint.

Jump to

Keyboard shortcuts

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