func (b *Balancer) SetMaxIdleConns(n int) {
	for _, db := range b.GetAllDbs() {
		db.Db.SetMaxIdleConns(n)
	}
}
SetMaxIdleConns sets the maximum number of connections
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the
new MaxIdleConns will be reduced to match the MaxOpenConns limit
If n <= 0, no idle connections are retained.
package gorb
import (
	"database/sql"
	"errors"
	"strings"
	"sync"
	"sync/atomic"
	"time"
	"github.com/go-gorp/gorp"
)
type Balancer struct {
	*gorp.DbMap    
	replicas      []*gorp.DbMap
	count         uint64
	mu            sync.RWMutex
	masterCanRead bool
}
func NewBalancer(driverName string, dialect gorp.Dialect, sources string) (*Balancer, error) {
	conns := strings.Split(sources, ";")
	if len(conns) == 0 {
		return nil, errors.New("empty servers list")
	}
	b := &Balancer{}
	for i, c := range conns {
		if len(c) == 0 {  
			continue
		}
		s, err := sql.Open(driverName, c)
		if err != nil {
			return nil, err
		}
		mapper := &gorp.DbMap{Db: s, Dialect: dialect}
		if i == 0 {  
			b.DbMap = mapper
		} else {
			b.replicas = append(b.replicas, mapper)
		}
	}
	if len(b.replicas) == 0 {
		b.replicas = append(b.replicas, b.DbMap)
		b.masterCanRead = true
	}
	return b, nil
}
func (b *Balancer) MasterCanRead(read bool) {
	b.mu.Lock()
	defer b.mu.Unlock()
	if read == true && b.masterCanRead == false {
		b.replicas = append(b.replicas, b.DbMap)
		b.masterCanRead = read
	}
	if read == false && b.masterCanRead == true && len(b.replicas) > 1 {
		replicas := []*gorp.DbMap{}
		for _, db := range b.replicas {
			if db != b.DbMap {
				replicas = append(replicas, db)
			}
		}
		b.replicas = replicas
		b.masterCanRead = read
	}
}
func (b *Balancer) Ping() error {
	var err, innerErr error
	for _, db := range b.GetAllDbs() {
		innerErr = db.Db.Ping()
		if innerErr != nil {
			err = innerErr
		}
	}
	return err
}