1 Star 0 Fork 0

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

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
DBConfig.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
dtal 提交于 2021-06-02 09:26 . init
package configuration
import (
"fmt"
"github.com/jinzhu/gorm"
"log"
"net/url"
)
type DBConfig struct {
}
func NewDBConfig() *DBConfig {
return &DBConfig{}
}
func (this *DBConfig) GormDB() *gorm.DB {
userName := GetYamlValue([]string{"config", "mysql", "username"}, 0, "root").(string)
password := GetYamlValue([]string{"config", "mysql", "password"}, 0, "aywc").(string)
host := GetYamlValue([]string{"config", "mysql", "host"}, 0, "47.116.71.194").(string)
port := GetYamlValue([]string{"config", "mysql", "port"}, 0, 3306).(int)
//db,err:=gorm.Open("mysql","root:root@tcp(192.168.101.95:3306)/aywc?charset=utf8mb4&parseTime=True&loc=Local")
//db,err:=gorm.Open("mysql","root:root@tcp(192.168.31.32:3306)/aywc?charset=utf8mb4&parseTime=True&loc=Local")
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))
db, err := gorm.Open("mysql", dsn)
if err != nil {
log.Fatal(err)
}
db.SingularTable(true)
db.DB().SetMaxIdleConns(50)
db.DB().SetMaxOpenConns(100)
db.LogMode(true)
return db
}
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

搜索帮助