connpool

package
v0.0.0-...-7686319 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option is the type for the functional options for the pool

func WithConnTimeout

func WithConnTimeout(connTimeout time.Duration) Option

WithConnTimeout sets the connTimeout option

func WithIdleConnTimeout

func WithIdleConnTimeout(idleConnTimeout time.Duration) Option

WithIdleConnTimeout sets the idleConnTimeout option

func WithMaxOpenConns

func WithMaxOpenConns(maxOpenConns int32) Option

WithMaxOpenConns sets the maxOpenConns option

func WithMaxRetry

func WithMaxRetry(maxRetry int32) Option

WithMaxRetry sets the maxRetry option

func WithPoolSize

func WithPoolSize(poolSize int32) Option

WithPoolSize sets the poolSize option

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) Option

WithReadTimeout sets the readTimeout option

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) Option

WithWriteTimeout sets the writeTimeout option

type Pool

type Pool interface {
	// Get returns a connection from the pool, the number of retries and a boolean indicating if the connection is new
	// It takes a context to control the deadline and timeout
	// It also takes an address to specify which host to connect
	Get(ctx context.Context, address string) (net.Conn, int32, bool, error)
	// Put returns a connection to the pool
	Put(net.Conn) error
	// Status returns a map of addresses and their connection status
	Status() map[string]*PoolStatus
}

Pool is the interface for a tcp connection pool

func NewPools

func NewPools(opts ...Option) Pool

NewPools creates a new pool with the given options

type PoolStatus

type PoolStatus struct {
	// PooledConns is the current number of connections in the pool
	PooledConns int32
	// OpenConns is the total number of connections for the address
	OpenConns int32
	// FreeCons is the total number of conntions that left could be opened.
	FreeConns int32
	// contains filtered or unexported fields
}

PoolStatus is a struct that contains the current pool size and total connection number for an address

Jump to

Keyboard shortcuts

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