Documentation
¶
Index ¶
- Variables
- type Close
- type ConnPool
- type Connection
- type Dial
- type EliminatedHook
- type Option
- func CoreNums(nums int) Option
- func DialBackoffPolicy(policy backoff.Policy) Option
- func EliminateAddr(maxErrorTimes int, maxErrorPeriod time.Duration, hook EliminatedHook) Option
- func Lazy() Option
- func MaxIdleTime(d time.Duration) Option
- func MaxNums(nums int) Option
- func MaxWaitingCapacity(nums int) Option
- func WaitTimeout(d time.Duration) Option
- func WithWarmUp(wu WarmUp) Option
- type Registrar
- type WarmUp
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotUsableAddr represents all addresses has been eliminated from pool ErrNotUsableAddr = errors.New("not usable addr") // ErrPoolClosed represents the pool has been closed ErrPoolClosed = errors.New("pool closed") // ErrGetConnWaitTimeout represents get connection from pool timeout ErrGetConnWaitTimeout = errors.New("get connection wait timeout") // ErrIllegalAddress represents the specific address does not registered before pool.Get() called ErrIllegalAddress = errors.New("unknown address") // ErrAddrEliminated represents the address was eliminated ErrAddrEliminated = errors.New("address has been eliminated") )
Functions ¶
This section is empty.
Types ¶
type ConnPool ¶
type ConnPool interface { Get(addr ...string) (interface{}, error) Put(interface{}) Discard(interface{}) Close() }
ConnPool is an interface
type Connection ¶
type Connection interface { Value(k interface{}) interface{} WithValue(k, v interface{}) }
Connection is used to attach some information to the connection to relieve the pressure of the pool. Implements it to gain a better performance when the pool working in a heavily load. For example:
type Conn struct { ctx context.Context } func (c *Conn) Value(k interface{}) interface{} { return c.ctx.Value(k) } func (c *Conn) WithValue(k, v interface{}) { c.ctx = context.WithValue(c.ctx, k, v) }
type EliminatedHook ¶
type EliminatedHook = func(addr string)
type Option ¶
type Option func(p *pool)
Option pool option
func DialBackoffPolicy ¶
DialBackoffPolicy sets the backoff policy for dial error
func EliminateAddr ¶
func EliminateAddr(maxErrorTimes int, maxErrorPeriod time.Duration, hook EliminatedHook) Option
EliminateAddr eliminates the address from pool when an address dial error times greater than maxErrorTimes or continuous error duration greater than maxErrorPeriod
func MaxIdleTime ¶
MaxIdleTime sets a duration before an idle connection would be closed
func MaxWaitingCapacity ¶
MaxWaitingCapacity sets waiting request channel capacity
func WaitTimeout ¶
WaitTimeout sets max waiting time when get connection from pool
func WithWarmUp ¶
WithWarmUp sets warm up func to control the warming up connection pool