Help us shape the future of Go! Take the 2026 Go Developer Survey

gpol

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

gpol

golang connection pool

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("pool is closed")
)

Functions

This section is empty.

Types

type Config

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

连接池配置类

type ConnPool

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

连接池实现类

func (*ConnPool) Close

func (cp *ConnPool) Close(conn interface{}) error

关闭一个连接

func (*ConnPool) Get

func (cp *ConnPool) Get() (interface{}, error)

从连接池获取一个连接

func (*ConnPool) Len

func (cp *ConnPool) Len() int

获取当前连接池的大小

func (*ConnPool) Put

func (cp *ConnPool) Put(conn interface{}) error

添加一个连接到连接池

func (*ConnPool) Release

func (cp *ConnPool) Release() error

释放连接池

type Pool

type Pool interface {
	// 获取当前连接池大小
	Len() int

	// 添加一个连接到连接池
	Put(conn interface{}) error

	// 从连接池获取一个连接
	Get() (interface{}, error)

	// 关闭一个连接
	Close(conn interface{}) error

	// 释放连接池
	Release() error
}

连接池接口

func InitPool

func InitPool(config *Config) (Pool, error)

初始化连接池,创建一个连接池

Jump to

Keyboard shortcuts

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