pool

package
v0.0.0-...-b093af0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	//ErrClosed 连接池已经关闭Error
	ErrClosed        = errors.New("pool is closed")
	ErrRegisterPool  = errors.New("register pool error")
	ErrGetConnection = errors.New("get connection error")
	ErrPutConnection = errors.New("put connection error")
)

Functions

func GetMgoClient

func GetMgoClient(poolName string) (c *mongo.Client, err error)

func PutMgoClient

func PutMgoClient(poolName string, c *mongo.Client) (err error)

func RegisterMgoPool

func RegisterMgoPool(poolName string, url string, force bool, params ...int) (err error)

Types

type Config

type Config struct {
	//连接池中拥有的最小连接数
	InitialCap int
	//连接池中拥有的最大的连接数
	MaxCap int
	//生成连接的方法
	Factory func() (interface{}, error)
	//关闭连接的方法
	Close func(interface{}) error
	//检查连接是否有效的方法
	Ping func(interface{}) error
	//连接最大空闲时间,超过该事件则将失效
	IdleTimeout time.Duration
}

Config 连接池相关配置

type Pool

type Pool interface {
	Get() (interface{}, error)

	Put(interface{}) error

	Close(interface{}) error

	Release()

	Len() int
}

Pool 基本方法

func NewChannelPool

func NewChannelPool(poolConfig *Config) (Pool, error)

NewChannelPool 初始化连接

Jump to

Keyboard shortcuts

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