getcdv3

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package grpcpool provides a pool of grpc clients

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is the error when the client pool is closed
	ErrClosed = errors.New("grpc pool: client pool is closed")
	// ErrTimeout is the error when the client pool timed out
	ErrTimeout = errors.New("grpc pool: client pool timed out")
	// ErrAlreadyClosed is the error when the client conn was already closed
	ErrAlreadyClosed = errors.New("grpc pool: the connection was already closed")
	// ErrFullPool is the error when the pool is already full
	ErrFullPool = errors.New("grpc pool: closing a ClientConn into a full pool")
)

Functions

func GetPrefix

func GetPrefix(schema, serviceName string) string

"%s:///%s/"

func GetPrefix4Unique

func GetPrefix4Unique(schema, serviceName string) string

"%s:///%s"

func WithRequestMateData added in v1.0.3

func WithRequestMateData() grpc.DialOption

Types

type ClientConn

type ClientConn struct {
	*grpc.ClientConn
	// contains filtered or unexported fields
}

ClientConn is the wrapper for a grpc client conn

func (*ClientConn) Close

func (c *ClientConn) Close() error

Close returns a ClientConn to the pool. It is safe to call multiple time, but will return an error after first time

func (*ClientConn) Unhealthy

func (c *ClientConn) Unhealthy()

Unhealthy marks the client conn as unhealthy, so that the connection gets reset when closed

type EtcdConn added in v1.0.4

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

func NewEtcdConn added in v1.0.4

func NewEtcdConn(schema, etcdAddr, host, userName, password string, port, ttl int) (conn *EtcdConn, err error)

func (*EtcdConn) GetConn added in v1.0.4

func (e *EtcdConn) GetConn(operationID, serviceName string) *grpc.ClientConn

func (*EtcdConn) GetDefaultEtcdConfig added in v1.0.4

func (e *EtcdConn) GetDefaultEtcdConfig(serviceName string) []int

func (*EtcdConn) GetDefaultGatewayConn4Unique added in v1.0.4

func (e *EtcdConn) GetDefaultGatewayConn4Unique(operationID string, serviceName string) []*grpc.ClientConn

func (*EtcdConn) GetTarget added in v1.0.4

func (e *EtcdConn) GetTarget(serviceName string) string

func (*EtcdConn) NewResolver added in v1.0.4

func (e *EtcdConn) NewResolver(operationID string, serviceName string) (*Resolver, error)

func (*EtcdConn) RegisterEtcd added in v1.0.4

func (e *EtcdConn) RegisterEtcd(operationID, serviceName string) error

etcdAddr separated by commas

func (*EtcdConn) RegisterEtcd4Unique added in v1.0.4

func (e *EtcdConn) RegisterEtcd4Unique(operationID, serviceName string) error

"%s:///%s/" -> "%s:///%s:ip:port"

func (*EtcdConn) SetDefaultEtcdConfig added in v1.0.4

func (e *EtcdConn) SetDefaultEtcdConfig(serviceName string, defaultPorts []int)

func (*EtcdConn) UnRegisterEtcd added in v1.0.4

func (e *EtcdConn) UnRegisterEtcd() error

type Factory

type Factory func(schema, etcdaddr, servicename string) (*grpc.ClientConn, error)

Factory is a function type creating a grpc client

type FactoryWithContext

type FactoryWithContext func(context.Context) (*grpc.ClientConn, error)

FactoryWithContext is a function type creating a grpc client that accepts the context parameter that could be passed from Get or NewWithContext method.

type Pool

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

Pool is the grpc client pool

func New

func New(factory Factory, schema, etcdaddr, servicename string, init, capacity int, idleTimeout time.Duration,
	maxLifeDuration ...time.Duration) (*Pool, error)

New creates a new clients pool with the given initial and maximum capacity, and the timeout for the idle clients. Returns an error if the initial clients could not be created

func NewWithContext

func NewWithContext(ctx context.Context, factory FactoryWithContext, init, capacity int, idleTimeout time.Duration,
	maxLifeDuration ...time.Duration) (*Pool, error)

NewWithContext creates a new clients pool with the given initial and maximum capacity, and the timeout for the idle clients. The context parameter would be passed to the factory method during initialization. Returns an error if the initial clients could not be created.

func (*Pool) Available

func (p *Pool) Available() int

Available returns the number of currently unused clients

func (*Pool) Capacity

func (p *Pool) Capacity() int

Capacity returns the capacity

func (*Pool) Close

func (p *Pool) Close()

Close empties the pool calling Close on all its clients. You can call Close while there are outstanding clients. The pool channel is then closed, and Get will not be allowed anymore

func (*Pool) Get

func (p *Pool) Get(ctx context.Context) (*ClientConn, error)

Get will return the next available client. If capacity has not been reached, it will create a new one using the factory. Otherwise, it will wait till the next client becomes available or a timeout. A timeout of 0 is an indefinite wait

func (*Pool) IsClosed

func (p *Pool) IsClosed() bool

IsClosed returns true if the client pool is closed.

type RegEtcd

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

type Resolver

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

func (*Resolver) Build

func (*Resolver) Close

func (r *Resolver) Close()

func (*Resolver) ResolveNow

func (r *Resolver) ResolveNow(rn resolver.ResolveNowOptions)

func (*Resolver) Scheme

func (r *Resolver) Scheme() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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