endpoints

package
v0.0.0-...-ae0dd77 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasterSlaveClusters = MasterCluster | SlaveCluster
)

Variables

View Source
var (
	ErrFailoverUnavailable = xerrors.New("no endpoint is available for failover")
)

Functions

func WrapHTTPClient

func WrapHTTPClient(client *http.Client, headers map[string]string, rps int) *http.Client

Types

type ClientOption

type ClientOption func(opts *clientOptions)

type ClusterIdentity

type ClusterIdentity int
const (
	MasterCluster ClusterIdentity = 1 << iota
	SlaveCluster
	ValidatorCluster
	ConsensusCluster
)

type Endpoint

type Endpoint struct {
	Name   string
	Config *config.Endpoint
	Client *http.Client
	// contains filtered or unexported fields
}

func (*Endpoint) IncRequestsCounter

func (e *Endpoint) IncRequestsCounter(n int64)

type EndpointProvider

type EndpointProvider interface {
	GetEndpoint(ctx context.Context) (*Endpoint, error)
	GetAllEndpoints() []*Endpoint
	GetActiveEndpoints(ctx context.Context) []*Endpoint
	WithFailoverContext(ctx context.Context) (context.Context, error)
	HasFailoverContext(ctx context.Context) bool
}

EndpointProvider encapsulates the client-side routing logic. By default, the request is routed to one of the primary endpoints based on their weights. When the failover context is seen, the request is instead routed to one of the secondary endpoints. In most cases, the primary endpoints are referring to the `EndpointGroup.Endpoints` config, while the secondary endpoints are referring to the `EndpointGroup.EndpointsFailover` config. But when `EndpointGroup.UseFailover` is turned on, the two list are swapped.

type EndpointProviderParams

type EndpointProviderParams struct {
	fx.In
	Config *config.Config
	Logger *zap.Logger
	Scope  tally.Scope
}

type EndpointProviderResult

type EndpointProviderResult struct {
	fx.Out
	Master    EndpointProvider `name:"master"`
	Slave     EndpointProvider `name:"slave"`
	Validator EndpointProvider `name:"validator"`
	Consensus EndpointProvider `name:"consensus"`
}

func NewEndpointProvider

func NewEndpointProvider(params EndpointProviderParams) (EndpointProviderResult, error)

type FailoverManager

type FailoverManager interface {
	WithFailoverContext(ctx context.Context, cluster ClusterIdentity) (context.Context, error)
}

func NewFailoverManager

func NewFailoverManager(params FailoverManagerParams) FailoverManager

type FailoverManagerParams

type FailoverManagerParams struct {
	fx.In
	Master    EndpointProvider `name:"master"`
	Slave     EndpointProvider `name:"slave"`
	Validator EndpointProvider `name:"validator"`
	Consensus EndpointProvider `name:"consensus"`
}

type RosettaEndpointProvider

type RosettaEndpointProvider interface {
	GetEndpoint(ctx context.Context) (*Endpoint, *rc.APIClient, error)
}

type RosettaEndpointsParams

type RosettaEndpointsParams struct {
	fx.In
	Master    EndpointProvider `name:"master"`
	Slave     EndpointProvider `name:"slave"`
	Validator EndpointProvider `name:"validator"`
	Consensus EndpointProvider `name:"consensus"`
}

type RosettaEndpointsResult

type RosettaEndpointsResult struct {
	fx.Out
	Master    RosettaEndpointProvider `name:"master"`
	Slave     RosettaEndpointProvider `name:"slave"`
	Validator RosettaEndpointProvider `name:"validator"`
	Consensus RosettaEndpointProvider `name:"consensus"`
}

func NewRosettaEndpointProvider

func NewRosettaEndpointProvider(params RosettaEndpointsParams) (RosettaEndpointsResult, error)

Jump to

Keyboard shortcuts

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