package main
import (
"fmt""log""github.com/StudioSol/balancer"
)
funcmain() {
config:= balancer.Config{
// Time in seconds in wich the health of the slaves is going to be checkedCheckInterval: 3,
// Wether the balancer should start checking healthStartCheck: true,
// Wether the queries executed by the balancer server should be loggedTraceOn: false,
// A balancer.Logger interface implementationLogger: log,
// Slave servers' configurationServersSettings: []balancer.ServerSettings{
balancer.ServerSettings{
// Name of the MySQL Slave ServerName: "slave 1",
// Connection string of the MySQL user used for readingDSN: "user:password@tcp(127.0.0.1:3306)/database",
// Connection string of the MySQL user used for status. The chosen// user must have "REPLICATION STATUS" permissionReplicationDSN: "replication_user:password@tcp(127.0.0.1:3306)/",
// Maximum idle connectionsMaxIdleConns: 0,
// Maximum open connectionsMaxOpenConns: 10,
},
// ...
}
db:=balancer.New(config)
server:=db.PickServer()
ifserver!=nil {
fmt.Println("No Server avaliable", server)
}
// Be happy! :)server.GetConnection().SelectOne(
// ...
)
}