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