README
¶
Mysql
package main
import (
"context"
"github.com/joshqu1985/fireman/configor"
"github.com/joshqu1985/fireman/store/mysql"
)
type Config struct {
Mysql []mysql.Config
}
var (
Conf Config
)
func init() {
if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
panic(err)
}
}
type Account struct {
Uid string `json:"uid"`
Phone string `json:"phone"`
}
func main() {
pool := mysql.NewPool(Conf.Mysql)
item := &Account{}
handle := func(orm *mysql.DB) error {
return orm.Where("uid=?", uid).Find(item).Error
}
err := pool.Slave("accounts").Doit(context.Background(), handle)
fmt.Prinln(item, err)
}
#conf.toml
[[mysql]]
name = "uauth"
opts = "charset=utf8mb4"
[mysql.master]
host = "127.0.0.1:3306"
auth = "root:"
max_idle = 5
max_open = 30
max_life = 600
[[mysql.slave]]
host = "127.0.0.1:3306"
auth = "root:"
max_idle = 5
max_open = 30
max_life = 600
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrRecordNotFound = errors.New("record not found")
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Name string Opts string Master ConfigNode Slaves []ConfigNode }
type ConfigNode ¶
Click to show internal directories.
Click to hide internal directories.