func (cp *connectionPoolImpl) Get(ctx context.Context) (PooledConnect, error) {
	p := cp.pool()
	if p == nil {
		return nil, ErrConnectionPoolClosed
	}
	getCtx, cancel := context.WithTimeout(ctx, getConnTimeout)
	defer cancel()
	r, err := p.Get(getCtx)
	if err != nil {
		return nil, err
	}
	return r.(*pooledConnectImpl), nil
}
Get return a connection, you should call PooledConnect's Recycle once done
package backend
import (
	"context"
	"errors"
	"sync"
	"time"
	"github.com/XiaoMi/Gaea/mysql"
	"github.com/XiaoMi/Gaea/util"
)
const (
	getConnTimeout = 2 * time.Second
)
var (
	ErrConnectionPoolClosed = errors.New("connection pool is closed")
	DefaultCapacity = 64
)
type connectionPoolImpl struct {
	mu          sync.RWMutex
	connections *util.ResourcePool
	addr     string
	user     string
	password string
	db       string
	charset     string
	collationID mysql.CollationID
	capacity    int  
	maxCapacity int  
	idleTimeout time.Duration
}
func NewConnectionPool(addr, user, password, db string, capacity, maxCapacity int, idleTimeout time.Duration, charset string, collationID mysql.CollationID) ConnectionPool {
	cp := &connectionPoolImpl{addr: addr, user: user, password: password, db: db, capacity: capacity, maxCapacity: maxCapacity, idleTimeout: idleTimeout, charset: charset, collationID: collationID}
	return cp
}
func (cp *connectionPoolImpl) pool() (p *util.ResourcePool) {
	cp.mu.Lock()
	p = cp.connections
	cp.mu.Unlock()
	return p
}
func (cp *connectionPoolImpl) Open() {
	if cp.capacity == 0 {
		cp.capacity = DefaultCapacity
	}
	if cp.maxCapacity == 0 {
		cp.maxCapacity = cp.capacity
	}
	cp.mu.Lock()
	defer cp.mu.Unlock()
	cp.connections = util.NewResourcePool(cp.connect, cp.capacity, cp.maxCapacity, cp.idleTimeout)
	return
}
func (cp *connectionPoolImpl) connect() (util.Resource, error) {
	c, err := NewDirectConnection(cp.addr, cp.user, cp.password, cp.db, cp.charset, cp.collationID)
	if err != nil {
		return nil, err
	}
	return &pooledConnectImpl{directConnection: c, pool: cp}, nil
}
func (cp *connectionPoolImpl) Addr() string {
	return cp.addr
}
func (cp *connectionPoolImpl) Close() {
	p := cp.pool()
	if p == nil {
		return
	}
	p.Close()
	cp.mu.Lock()
	cp.connections = nil
	cp.mu.Unlock()
	return
}
func (cp *connectionPoolImpl) tryReuse(pc *pooledConnectImpl) error {
	return pc.directConnection.ResetConnection()
}