go get -u -v github.com/danteay/gomysql
And import in your files whit the next lines:
import (
"database/sql"
"github.com/danteay/gomysql"
)
Setup config for circut and recover strategies
conf := gomysql.MysqlOptions{
Url: "user:password@/dbname",
Poolsize: 10,
FailRate: 0.25,
Regenerate: time.Second * 5,
TimeOut: time.Second * 1,
}
Init connection pool
pool, err := gomysql.InitPool(conf)
if err != nil {
fmt.Println(err)
}
Execute querys inside of the circuit breaker
var suma int
errQuery := pool.Execute(func(db *sql.DB) error {
fmt.Println("Entra callback")
return db.QueryRow("SELECT 1+1 AS suma").Scan(&suma)
})
if errQuery != nil {
fmt.Println(errQuery)
}
Healt check of the pool connection
fmt.Println("==>> State: ", pool.State())