pool

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPoolClosed is returned when pool is closed
	ErrPoolClosed = errors.New("connection pool is closed")

	// ErrPoolExhausted is returned when pool has no available connections
	ErrPoolExhausted = errors.New("connection pool exhausted")

	// ErrConnectionInvalid is returned when connection is invalid
	ErrConnectionInvalid = errors.New("connection is invalid")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxIdle is maximum number of idle connections
	MaxIdle int

	// MaxOpen is maximum number of open connections
	MaxOpen int

	// MaxLifetime is maximum connection lifetime
	MaxLifetime time.Duration

	// MaxIdleTime is maximum idle time before closing
	MaxIdleTime time.Duration

	// WaitTimeout is maximum wait time for connection
	WaitTimeout time.Duration
}

Config configures connection pool

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default pool configuration

type Connection

type Connection interface {
	// Close closes the connection
	Close() error

	// IsValid checks if connection is valid
	IsValid() bool

	// Reset resets connection state for reuse
	Reset() error
}

Connection represents a pooled connection

type Factory

type Factory interface {
	// Create creates a new connection
	Create() (Connection, error)

	// Validate checks if connection is valid
	Validate(conn Connection) bool
}

Factory creates new connections

type Pool

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

Pool is a generic connection pool

func NewPool

func NewPool(factory Factory, config Config) *Pool

NewPool creates a new connection pool

func (*Pool) CleanupStale

func (p *Pool) CleanupStale() int

CleanupStale removes stale connections from pool

func (*Pool) Close

func (p *Pool) Close() error

Close closes the pool and all connections

func (*Pool) Get

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

Get retrieves a connection from pool

func (*Pool) GetMetrics

func (p *Pool) GetMetrics() *metrics.Metrics

GetMetrics returns pool metrics

func (*Pool) Put

func (p *Pool) Put(conn Connection) error

Put returns a connection to pool

func (*Pool) StartCleaner

func (p *Pool) StartCleaner(interval time.Duration) chan struct{}

StartCleaner starts background cleaner goroutine

func (*Pool) Stats

func (p *Pool) Stats() PoolStats

Stats returns pool statistics

type PoolStats

type PoolStats struct {
	OpenConnections int `json:"open_connections"`
	IdleConnections int `json:"idle_connections"`
	WaitingRequests int `json:"waiting_requests"`
	MaxOpenConns    int `json:"max_open_conns"`
	MaxIdleConns    int `json:"max_idle_conns"`
}

PoolStats represents pool statistics

Jump to

Keyboard shortcuts

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