12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package parser
- import (
- "property-system/config"
- "git.getensh.com/common/gopkgs/database"
- )
- var mysqlConfig config.MysqlConfig
- func MysqlHandler(conf *config.Configure) {
- // mysqlConfig.Addr 不为空表示已经初始化
- if mysqlConfig.Addr != "" {
- // 地址,用户名,密码相同比较其他配置是否一致
- sqlDB, _ := database.DB().DB()
- if mysqlConfig.User == conf.Mysql.User &&
- mysqlConfig.Password == conf.Mysql.Password &&
- mysqlConfig.Addr == conf.Mysql.Addr {
- if mysqlConfig.MaxIdle != conf.Mysql.MaxIdle {
- sqlDB.SetMaxIdleConns(conf.Mysql.MaxIdle)
- }
- if mysqlConfig.MaxConn != conf.Mysql.MaxConn {
- sqlDB.SetMaxOpenConns(conf.Mysql.MaxConn)
- }
- if mysqlConfig.LogMode != conf.Mysql.LogMode {
- //database.DB().LogMode(conf.Mysql.LogMode)
- }
- return // 这里直接返回
- }
- // 地址用户名密码不一致,关闭连接重新连接
- sqlDB.Close()
- }
- // 私有db为空使用公共db
- dbname := conf.Rpc.System.MysqlDb
- if dbname == "" {
- dbname = conf.Mysql.DB
- }
- // 连接database
- database.Setup(conf.Mysql.User,
- conf.Mysql.Password,
- conf.Mysql.Addr,
- dbname,
- conf.Mysql.Charset,
- conf.Mysql.MaxIdle,
- conf.Mysql.MaxConn,
- conf.Mysql.LogMode)
- mysqlConfig = conf.Mysql
- }
|