Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGroupNotExist returned when the group hasn't been created ErrGroupNotExist = errors.New("group doesn't exist") // ErrConnectionNotExists returned when the connection doesn't exist or has already been closed ErrConnectionNotExists = errors.New("connection doesn't exist") // ErrCouldNotAssignConnection when connection assignment fails ErrCouldNotAssignConnection = errors.New("assigning connection to gRPC client failed") // ErrInvalidConnectionPool returwhen the type assertion to ConnectionPool fails ErrInvalidConnectionPool = errors.New("invalid connection pool") )
var ( // ErrConnectionClosed is returned when the pool is closed ErrConnectionClosed = errors.New("connections closed") )
Functions ¶
This section is empty.
Types ¶
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn holds the function created by the pool factory method. It also keeps the address, and a reference to the parent pool
func (*ClientConn) Address ¶
func (cc *ClientConn) Address() string
Address returns the factory connection address
func (*ClientConn) Close ¶
func (cc *ClientConn) Close() error
Close - closes the connection to the gRPC service server
func (*ClientConn) Conn ¶
func (cc *ClientConn) Conn() FactoryConn
Conn returns the factory connection
type CloseFunc ¶
type CloseFunc func(conn interface{}) error
CloseFunc to close the connection in the pool
type Connection ¶
type Connection interface { // Address returns the connection address Address() string // Conn returns the factory connection Conn() FactoryConn // Close connection Close() error }
Connection interface is the connection saved in the pool
type ConnectionPool ¶
type ConnectionPool struct { CloseFunc CloseFunc sync.RWMutex // contains filtered or unexported fields }
ConnectionPool holds the connections in the pool, alongwith the factory to create a new connection, size of each type of connection in the pool, and the CloseFunc callback used to close a specific connection in the pool
func NewPool ¶
func NewPool(opts ...Option) *ConnectionPool
NewPool creates a new pool with size and factory
func (*ConnectionPool) Close ¶
func (p *ConnectionPool) Close() error
Close - closes the connection pool and all it's channels
func (*ConnectionPool) Get ¶
func (p *ConnectionPool) Get(address string) (Connection, error)
Get creates or returns an existing gRPC client connection
type Factory ¶
type Factory func(address string) (FactoryConn, error)
Factory callback creates and returns a new connection
type FactoryConn ¶
type FactoryConn interface{}
FactoryConn interface is the connection returned by the factory passed to the pool
type Option ¶
type Option func(*ConnectionPool)
Option to pass as arg while creating new service
func WithCloseFunc ¶
WithCloseFunc passes the CloseFunc callback to the pool
func WithFactory ¶
WithFactory defines the connection creation factory
func WithLogger ¶
WithLogger sets the logger for the pool