12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package parser
- import (
- "adm-vehicle-style/config"
- "git.getensh.com/common/gopkgsv2/database"
- )
- var mysqlConfig config.MysqlConfig
- func MysqlHandler(conf *config.Configure) {
- // mysqlConfig.Addr 不为空表示已经初始化
- if mysqlConfig.Addr != "" {
- sqlDB, err := database.DB().DB()
- if err != nil {
- return
- }
- // 地址,用户名,密码相同比较其他配置是否一致
- 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().Debug()
- }
- return // 这里直接返回
- }
- // 地址用户名密码不一致,关闭连接重新连接
- _ = sqlDB.Close()
- }
- // 私有db为空使用公共db
- dbname := conf.Rpc.ADMVehicleStyle.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
- }
|