// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package parser import ( "cp-organization-management-gateway/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.CpOrganizationManagementGateway.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 }