1 Star 0 Fork 0

江苏艾雨文承养老机器人有限公司/aywc_judge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DBInit.go 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
dtal 提交于 2021-06-02 14:21 +08:00 . mtt0408--aywc_1 更改工作目录
package appinit
import (
"fmt"
"gitee.com/aywc_1/aywc_judge/src/configuration"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"net/url"
)
var db *sqlx.DB
var sdDB *sqlx.DB
func DBInit() error {
userName := configuration.GetYamlValue([]string{"config", "mysql", "username"}, 0, "root").(string)
password := configuration.GetYamlValue([]string{"config", "mysql", "password"}, 0, "aywc").(string)
host := configuration.GetYamlValue([]string{"config", "mysql", "host"}, 0, "47.116.71.194").(string)
port := configuration.GetYamlValue([]string{"config", "mysql", "port"}, 0, 3306).(int)
timezone := "'Asia/Shanghai'"
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/aywc?charset=utf8mb4&parseTime=True&loc=Local&time_zone=%s", userName, password, host, port, url.QueryEscape(timezone))
var err error
db, err = sqlx.Connect("mysql",
dsn)
if err != nil {
return err
}
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(5)
return nil
}
func SDDBInit() error {
userName := configuration.GetYamlValue([]string{"config", "mysql", "username"}, 0, "root").(string)
password := configuration.GetYamlValue([]string{"config", "mysql", "password"}, 0, "aywc").(string)
host := configuration.GetYamlValue([]string{"config", "mysql", "host"}, 0, "47.116.71.194").(string)
port := configuration.GetYamlValue([]string{"config", "mysql", "port"}, 0, 3306).(int)
timezone := "'Asia/Shanghai'"
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/sdcc25?charset=utf8mb4&parseTime=True&loc=Local&time_zone=%s", userName, password, host, port, url.QueryEscape(timezone))
var err error
db, err = sqlx.Connect("mysql",
dsn)
if err != nil {
return err
}
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(5)
return nil
}
func GetDB() *sqlx.DB {
return db
}
func GetSdDB() *sqlx.DB {
return sdDB
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/aywc_1/aywc_judge.git
git@gitee.com:aywc_1/aywc_judge.git
aywc_1
aywc_judge
aywc_judge
v0.6.11

搜索帮助