go_pool

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 9 Imported by: 0

README

go_pool

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig  = errors.New("invalid pool config")
	ErrPoolClosed     = errors.New("pool closed")
	ErrGetConnTimeout = errors.New("get conn timeout")
	ErrConnFactory    = errors.New("ConnFactory error")
	ErrNoAliveHost    = errors.New("there is no alive host")
)

Functions

This section is empty.

Types

type ConnFactory

type ConnFactory func() (io.Closer, error)

创建连接的方法

func ConnFactoryGrpc

func ConnFactoryGrpc(getHostsFunc GetHostsFunc) ConnFactory

type ConnTestFunc

type ConnTestFunc func(closer io.Closer) bool

判断连接是否可用

type GetHostsFunc

type GetHostsFunc func() (hosts []string, err error)

func GetHostsFuncFromConsul

func GetHostsFuncFromConsul(consulClient *api.Client, ServiceId string) GetHostsFunc

type Option

type Option interface {
	// contains filtered or unexported methods
}

type OptionConnMaxAliveTime

type OptionConnMaxAliveTime time.Duration

连接最大存活时间

type OptionGetConnWaitDeadline

type OptionGetConnWaitDeadline time.Duration

获取连接最大等待时间

type OptionMaxOpen

type OptionMaxOpen int

池中最大资源数

type OptionMinOpen

type OptionMinOpen int

池中最少资源数

type Pool

type Pool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPool

func NewPool(factory ConnFactory, connTestFunc ConnTestFunc, options ...Option) (*Pool, error)

func (*Pool) Acquire

func (p *Pool) Acquire() (io.Closer, error)

func (*Pool) Close

func (p *Pool) Close() error

关闭连接池,释放所有资源

func (*Pool) CloseOne

func (p *Pool) CloseOne(closer io.Closer)

func (*Pool) Release

func (p *Pool) Release(closer io.Closer)

释放单个资源到连接池

Jump to

Keyboard shortcuts

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