Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
November 5, 2019 14:52
February 16, 2020 19:52
October 11, 2020 11:54
November 13, 2016 15:48
October 14, 2020 10:35
October 11, 2020 11:54
February 13, 2020 22:22
February 16, 2020 19:52
October 11, 2020 11:54


PkgGoDev Go Report Card


A golang universal network connection pool.


  • More versatile, The connection type in the connection pool is interface{}, making it more versatile
  • More configurable, The connection supports setting the maximum idle time, the timeout connection will be closed and discarded, which can avoid the problem of automatic connection failure when idle
  • Support user setting ping method, used to check the connectivity of connection, invalid connection will be discarded
  • Support connection waiting, When the connection pool is full, support for connection waiting (like the go db connection pool)

Basic Usage:

//factory Specify the method to create the connection
factory := func() (interface{}, error) { return net.Dial("tcp", "") }

//close Specify the method to close the connection
close := func(v interface{}) error { return v.(net.Conn).Close() }

//ping Specify the method to detect whether the connection is invalid
//ping := func(v interface{}) error { return nil }

//Create a connection pool: Initialize the number of connections to 5, the maximum idle connection is 20, and the maximum concurrent connection is 30
poolConfig := &pool.Config{
	InitialCap: 5,
	MaxIdle:   20,
	MaxCap:     30,
	Factory:    factory,
	Close:      close,
	//Ping:       ping,
	//The maximum idle time of the connection, the connection exceeding this time will be closed, which can avoid the problem of automatic failure when connecting to EOF when idle
	IdleTimeout: 15 * time.Second,
p, err := pool.NewChannelPool(poolConfig)
if err != nil {
	fmt.Println("err=", err)

//Get a connection from the connection pool
v, err := p.Get()

//do something

//Put the connection back into the connection pool, when the connection is no longer in use

//Release all connections in the connection pool, when resources need to be destroyed

//View the number of connections in the current connection pool
current := p.Len()


The connection pool implementation refers to pool , thanks.


The MIT License (MIT) - see LICENSE for more details